sql查詢練習(xí)題含答案.doc_第1頁
sql查詢練習(xí)題含答案.doc_第2頁
sql查詢練習(xí)題含答案.doc_第3頁
sql查詢練習(xí)題含答案.doc_第4頁
sql查詢練習(xí)題含答案.doc_第5頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、-(1)    查詢20號部門的所有員工信息。select * from emp e where =20;-(2)    查詢獎金(COMM)高于工資(SAL)的員工信息。select * from emp where comm>sal;-(3)    查詢獎金高于工資的20%的員工信息。select * from emp where comm>sal*;-(4)    查詢10號部門中工種為MANAGER和20號部門中工種為CLERK的員工的信息。select * from emp e where =

2、10 and ='MANAGER') or =20 and ='CLERK')-(5)    查詢所有工種不是MANAGER和CLERK,-且工資大于或等于2000的員工的詳細(xì)信息。select * from emp where job not in('MANAGER','CLERK') and sal>=2000;-(6)    查詢有獎金的員工的不同工種。select * from emp where comm is not null;-(7)    查詢所有員

3、工工資和獎金的和。select nvl,0) from emp e;-(8)    查詢沒有獎金或獎金低于100的員工信息。select * from emp where comm is null or comm<100;-(9)    查詢員工工齡大于或等于10年的員工信息。select * from emp where (sysdate-hiredate)/365>=10;-(10)    查詢員工信息,要求以首字母大寫的方式顯示所有員工的姓名。select initcap(ename) from emp;select

4、 upper(substr(ename,1,1)|lower(substr(ename,2) from emp;-(11)    顯示所有員工的姓名、入職的年份和月份,按入職日期所在的月份排序,-若月份相同則按入職的年份排序。select ename,to_char(hiredate,'yyyy') year,to_char(hiredate,'MM') month from emporder by month,year;-(12)    查詢在2月份入職的所有員工信息。select * from emp where to

5、_char(hiredate,'MM')='02'-(13)    查詢所有員工入職以來的工作期限,用“*年*月*日”的形式表示。select ,floor(/365)|'年'|floor(mod(,365)/30)|'月'|floor(mod(mod(,365),30)|'日' from emp e;-(14)    查詢從事同一種工作但不屬于同一部門的員工信息。select ,from emp a,emp bwhere = and <>-(15) 

6、  查詢各個部門的詳細(xì)信息以及部門人數(shù)、部門平均工資。select ,count,avg, from emp e ,dept dwhere =group by ,-(16)    查詢10號部門員工以及領(lǐng)導(dǎo)的信息。select * from emp where empno in(select mgr from emp where deptno=10) or deptno=10;-(17)    查詢工資為某個部門平均工資的員工信息。select * from empwhere sal in(select avg(sal) from emp gr

7、oup by deptno);-(18)    查詢工資高于本部門平均工資的員工的信息。select * from emp e1 where sal >(select avg(sal) from emp e2 where =;-(19)    查詢工資高于本部門平均工資的員工的信息及其部門的平均工資。select e.*, from emp e,(select deptno,avg(sal) as avgsal from emp group by deptno) awhere = and >-(20)    統(tǒng)計各個工種的

8、人數(shù)與平均工資。select count(*),avg from emp e group by -(21)    統(tǒng)計每個部門中各個工種的人數(shù)與平均工資。select deptno,job,count(empno),avg(sal) from emp egroup by ,-(22)    查詢所有員工工資都大于1000的部門的信息。select * from dept where deptno in(select deptno from empwhere deptno not in (select distinct deptno from emp wh

9、ere sal<1000);-(23)    查詢所有員工工資都大于1000的部門的信息及其員工信息。select * from emp e join dept don in (select deptno from empwhere deptno not in (select distinct deptno from emp where sal<1000)and =;-(24)    查詢所有員工工資都在9003000之間的部門的信息。select * from dept where deptno not in(select deptno f

10、rom emp where sal not between 900 and 3000);-(25)    查詢所有工資都在9003000之間的員工所在部門的員工信息。select * from emp awhere  in(select distinct  from emp e where  between 900 and 3000); -(26)    查詢每個員工的領(lǐng)導(dǎo)所在部門的信息。select d.* from dept dwhere  in(select distinct  from emp e

11、1,emp e2where =;-(27)    查詢?nèi)藬?shù)最多的部門信息。select * from deptwhere deptno in(select deptno from (select count(*) count,deptno from emp group by deptno)where count in(select max(count) from (select count(*) count ,deptno from emp group by deptno);-(28)    查詢30號部門中工資排序前3名的員工信息。select * f

12、rom (select sal from emp where deptno=30 order by sal desc) ewhere rownum<4-(29)    查詢'JONES'員工及所有其直接、間接下屬員工的信息。select e.* from emp estart with ename='JONES'connect by prior empno=mgr;-(30)    查詢SCOTT員工及其直接、間接上級員工的信息。select e.* from emp estart with ename='S

13、COTT'connect by prior mgr=empno;-(31)    以樹狀結(jié)構(gòu)查詢所有員工與領(lǐng)導(dǎo)之間的層次關(guān)系。select substr(sys_connect_by_path(ename,'->'),3),levelfrom empstart with mgr is nullconnect by prior empno=mgr;-(32)向emp表中插入一條記錄,員工號為1357,員工名字為oracle,-工資為2050元,部門號為20,入職日期為2002年5月10日。-(33)將各部門員工的工資修改為該員工所在部門平均工資加

14、1000。update emp e set sal=1000 (select avg(sal) from emp where deptno=;-(34)查詢工作等級為2級,1985年以后入職的工作地點為DALLAS的員工編號、-姓名和工資。select , from emp e,salgrade s,dept dwhere  between  and  and =2) and to_char,'yyyy')>1985and =and ='DALLAS'-35.部門平均薪水最高的部門編號select * from(select

15、avg(sal) avgsal,deptno from emp group by deptno order by avgsal desc)where rownum=1;select deptno,avg(sal) from emp group by deptno having avg(sal)=(  select max(avg(sal) avgsal from emp group by deptno)-36,部門平均薪水最高的部門名稱select d.* from dept d where deptno  in(    select deptno fr

16、om emp group by deptno having avg(sal)=(  select max(avg(sal) avgsal from emp group by deptno)-37.平均薪水最低的部門的部門名稱select d.* from dept d where deptno  in(    select deptno from emp group by deptno having avg(sal)=(  select  min(avg(sal) avgsal from emp group by deptno)-38

17、.平均薪水等級最低的部門的部門名稱select  from dept dwhere  in (select  from (select  from emp e,salgrade s where  between  and group by  order by avg) awhere rownum=1);-39.部門經(jīng)理人中,薪水最低的部門名稱select dname from dept where deptno=(select deptno from (select deptno from emp where job=

18、9;MANAGER' group by deptnoorder by min(sal) where rownum=1)-40.比普通員工的最高薪水還要高的經(jīng)理人名稱select ename from emp where sal>(select max(sal) from emp where job not in('MANAGER','PRESIDENT') and job='MANAGER' or job='PRESIDENT'-41.刪除重復(fù)部門,但是留下一項insert into dept values(70,'RESEARCH','DALLAS')select deptno,dname,rowid from deptdelete f

溫馨提示

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

評論

0/150

提交評論