国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Oracle > 正文

Oracle SQL語句

2024-08-29 13:53:44
字體:
來源:轉載
供稿:網友
ORDER BY 排序



ASC 升序(默認)

DESC 降序



select * from s_emp order by dept_id , salary desc
部門號升序,工資降序
關鍵字distinct也會觸發排序操作。



select * from employee order by 1; //按第一字段排序
NULL被認為無窮大。order by 可以跟別名。



select table_name from user_tables where table_name='S_EMP'; 查某個具體表名時,表名的字符串必須要為大寫
或者采用 upper(table_name)
select * from user_talbes where table_name like ‘s/_%’ escape ‘/’;
使用轉義字符對關鍵字進行轉義。

concat 連接字符串 select concat(first_name , last_name) from s_emp;等效于||

substr 求子串 select substr('tarenasd0603' ,1,6) from dual; (取前六個字符) select substr('tarenasd0603',-2) from dual; (取后兩個字符)

length 求字符長度
select length('zhonghua') from dual;

from dual的意思

虛表(dual)是Oracle提供的最小的工作表,它僅包含一行一列。對于虛表(dual)來說,其中的列往往是不相關的或無關緊要的。   
  如:查詢當前的系統日期   
  SQL>   select   sysdate   from   dual;   
    
  SYSDATE   
  -------------------   
  2004/04/28   08:49:41

round 函數(四舍五入) select round(45.935, 2) from dual; 不帶參數時默認為0位小數

trunc 函數(截取,不管后面的數字) select trunc(45.995, 1) from dual;

組函數

group by 分組子句 對分組后的子句進行過濾還可以用having 條件 對分組后的條件進行過濾 where 是對記錄進行過濾

有傭金人數的百分比

select count( commission_pct )count(*) from s_emp;

select count(dept_id) from s_emp;
select count(distinct dept_id) from s_emp;//區分相同的dept_id

求各個部門的平均工資:group by 子句也會觸發排序
select dept_id , avg(salary) aa from s_emp group by dept_id order by aa ; //對平均工資排序
select dept_id , avg(salary) aa from s_emp group by dept_id;

哪些部門的平均工資比2000高:
select dept_id, avg(salary) aa from s_emp group by (dept_id) having avg(salary)>2000;
除了42部門以外的部門的平均工資:
select dept_id , avg(salary) from s_emp group by (dept_id ) having dept_id!=42;

select dept_id , avg(salary) from s_emp where dept_id!=42 group by (dept_id ) ;(此種sql效率要高,先過濾) 再計算)

where 單行函數。
having 組函數。

每個員工所在的部門和部門所在的地區

select first_name , s_dept.name, s_region.name from s_emp, s_dept, s_region where
s_emp.dept_id=s_dept.id and s_dept.region_id=s_region.id;
等價于

select first_name,d.name,r.name
from s_emp e,s_dept d,s_region r
where e.dept_id=d.id and d.region_id=r.id;
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海阳市| 颍上县| 宣武区| 通许县| 涟源市| 郴州市| 新河县| 兴隆县| 德州市| 渝中区| 滨州市| 彭州市| 唐海县| 油尖旺区| 阳曲县| 乐至县| 文成县| 淮滨县| 镇江市| 察雅县| 章丘市| 永仁县| 磴口县| 南澳县| 乐东| 南皮县| 大庆市| 兴宁市| 宜君县| 措勤县| 鲁甸县| 安多县| 达州市| 项城市| 健康| 上蔡县| 孟州市| 保山市| 视频| 甘谷县| 沙湾县|