常用SQL查詢語句_第1頁
常用SQL查詢語句_第2頁
常用SQL查詢語句_第3頁
常用SQL查詢語句_第4頁
常用SQL查詢語句_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領

文檔簡介

1、descemp;select*fromemp;selectempmo,ename,mgrFROMemp;selectdistinctmgrFROMemp;-顯示非重復的數(shù)據(jù)SELECT*FROMempWHEREjob=CLERK;SELECTename,sal*13+nvl(comm,1)FROMemp;nvl(comm,1)的意思是,如果comm中有值,則nvl(comm,1)=comm;comm中無值,則nvl(comm,1)=0。SELECTename,sal*13+nvl(comm,0)year_salFROMemp;(year_sal為別名,可按別名排序)SELECT*FROMemp

2、WHEREhiredate01-1月-82;精品資料%表示一個或多個字符,_表示一個字符,charlist表示字符列中的任何單一字符,charlist或者!charlist不在字符列中的任何單一字符。SELECT*FROMempWHEREenamelikeS_T%;whereselect*fromempWHEREjobin(clerk,analyst);select*fromempwheremgris/isnotnull;select*fromempwhere(sal500orjob=MANGE)andenamelikej%;select*fromemporderbydeptno,salDES

3、C;(按部門升序,并按薪酬降序)selectmax(sal),min(age),avg(sal),sum(sal)fromemp;select*fromempwheresal=(selectmax(sal)fromemp);selectcount(*)fromemp;精品資料grouphavingselectdeptno,max(sal),avg(sal),fromempgroupbydeptno;selectdeptno,job,avg(sal),min(sal)fromempgroupbydeptno,jobhavingavg(sal)ALL(selectsalfromempwherede

4、ptno=30);或selectename,sal,deptnofromempwheresal(selectmax(sal)fromempwheredeptnp=30);查詢工資比部門號為30的所有員工工資都高的員工的姓名、薪水和部門號。以上兩個語句在功能上是一樣的,但執(zhí)行效率上,函數(shù)會高很多。selectename,sal,deptnofromempwheresalANY(selectsalfromempwheredeptno=30);或selectename,sal,deptnofromempwheresal(selectmin(sal)fromempwheredeptno=30);查詢工

5、資比部門號為30號的任意一個員工工資高(只要比某一員工工資高即可)的員工的姓名、薪水和部門號。以上兩個語句在功能上是一樣的,但執(zhí)行效率上,函數(shù)會高得多。select*fromempwhere(job,deptno)=(selectjob,deptnofromempwhereename=SMITH);精品資料selectemp.deptno,emp.ename,emp.sal,t_avgsal.avgsalfromemp,(selectemp.deptno,avg(emp.sal)avgsalfromempgroupbyemp.deptno)t_avgsalwhereemp.deptno=t_a

6、vgsal.deptnoANDemp.salt_avgsal.avgsalorderbyemp.deptno;數(shù)據(jù)庫的每行數(shù)據(jù)都有一個對應的行號,稱為rownumselecta2.*from(selecta1.*,ROWNUMrnfrom(select*fromempOrderbysal)a1whereRownum=6;指定查詢列、查詢結(jié)果排序等,都只需要修改最里層的子查詢即可createtablemytable(id,name,sal,job,deptno)asselectempno,ename,sal,job,deptnofromemp;selectename,sal,jobfromemp

7、wheresal2500UNION(INTERSECT/UNIONALL/MINUS)SELECTename,sal,jobfromempwherejob=manager;合并查詢的執(zhí)行效率遠高于and,or等邏輯查詢createtablemyEMP(empIDnumber(4),精品資料namevarchar2(20),salnumber(6),jobvarchar2(10),deptnumber(2);先建一張空表insertintomyEMP(empID,name,sal,job,dept)selectempno,ename,sal,job,deptnofromempwheredeptno=10;再將emp表中部門號為10的數(shù)據(jù)插入到新表myEMP中,實現(xiàn)數(shù)據(jù)的批量

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論