下的練習(xí)及答案_第1頁(yè)
下的練習(xí)及答案_第2頁(yè)
下的練習(xí)及答案_第3頁(yè)
下的練習(xí)及答案_第4頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

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

文檔簡(jiǎn)介

1、/*1、找出獎(jiǎng)金高于工資的員工*/ select * from emp where comm>sal;/*2、找出每個(gè)員工獎(jiǎng)金和工資的總和 */ select ename,decode(comm,null,0,comm)+sal from emp/*3、找出部門10中的經(jīng)理(MANAGER)和部門20中的普通員工(CLERK) */ select * from emp where deptno=10 and job='MANAGER' or deptno='20' and job='CLERK'/*4、找出部門10中既不是經(jīng)理也不是普通員工

2、,而且工資大于等于2000的員工 */ select * from emp where deptno=10 and job<>'MANAGER' and job<>'CLERK' and sal>=2000;select * from emp where deptno=10 and job not in ('MANAGER' ,'CLERK' )and sal>=2000;/*5、找出有獎(jiǎng)金的員工的不同工作 */ select distinct(job) from emp where comm

3、is not null /*6、找出沒有獎(jiǎng)金或者獎(jiǎng)金低于500的員工*/ select * from emp where comm is null or comm<500;/*7、顯示雇員姓名,根據(jù)其服務(wù)年限,將最老的雇員排在最前面 */ select ename,hiredate from emp order by hiredate,ename;/*8、找出每個(gè)月倒數(shù)第三天受雇的員工*/ select * from emp where hiredate = last_day(hiredate)-2;/*9、分別用case和decode函數(shù)列出員工所在的部門,deptno=10顯示

4、9;部門10', deptno=20顯示'部門20' deptno=30顯示'部門30' deptno=40顯示'部門40' 否則為'其他部門'*/ select ename,decode(deptno,10,'部門10',20,'部門20',30,'部門30',40,'部門40','其他部門') from emp;select ename,case deptno when 10 then '部門10' when 20 then

5、 '部門20' when 30 then '部門30' when 40 then '部門40' else '其他部門' end from emp;/*10、分組統(tǒng)計(jì)各部門下工資>1500的員工的平均工資*/ select deptno,avg(sal) from emp where sal>1500 group by deptno/*11、統(tǒng)計(jì)各部門下平均工資大于1500的部門*/ select deptno,avg(sal) from empgroup by deptnohaving avg(sal)>1500

6、;/*12、算出部門30中得到最多獎(jiǎng)金的員工獎(jiǎng)金 */ select max(comm) from emp where deptno=30/*13、算出部門30中得到最多獎(jiǎng)金的員工姓名*/ select ename,comm from emp where comm in(select max(comm) from emp where deptno=30)/*14、算出每個(gè)職位的員工數(shù)和最低工資*/ select job,count(*),min(sal) from empgroup by job;/*15、列出員工表中每個(gè)部門的員工數(shù),和部門no */ select deptno,count(

7、*) from emp group by deptno/*16、得到工資大于自己部門平均工資的員工信息*/ select * from emp e, (select avg(sal) b from emp group by deptno) awhere e.sal>a.b;/*17、分組統(tǒng)計(jì)每個(gè)部門下,每種職位的平均獎(jiǎng)金(也要算沒獎(jiǎng)金的人)和總工資(包括獎(jiǎng)金) */ select deptno,job ,avg(nvl(comm,0), sum(sal + nvl(comm, 0) from scott.emp group by deptno,job /*18、顯示員工ID,名字,直屬主

8、管ID,名字*/ select empno,ename,mgr, (select ename from emp e1 where e1.empno = e2.mgr)from emp e2 ;/*19、列出員工表中每個(gè)部門的員工數(shù),和部門no */ select deptno,count(*) from emp group by deptno/*20、列出員工表中每個(gè)部門的員工數(shù)(員工數(shù)必須大于3),和部門名稱*/ select e.deptno,d.dname,count(*) from emp e,dept dwhere e.deptno=d.deptnogroup by e.deptno

9、,d.dnamehaving count(*)>3;/*21、找出工資比jones多的員工*/ select * from emp ewhere e.sal>(select sal from emp where ename='JONES');/*22、列出所有員工的姓名和其上級(jí)的姓名 */ select a.ename 員工,b.ename 上級(jí) from emp a,emp bwhere b.empno=a.mgr;select * from emp;select ename, (select ename from emp e1 where e1.empno =

10、e2.mgr) from emp e2 /*23、以職位分組,找出平均工資最高的兩種職位 */ select avg(sal) from empgroup by job having avg(sal) in (select max(sal) from emp group by job)/*24、查找出不在部門20,且比部門20中任何一個(gè)人工資都高的員工姓名、部門名稱*/ select e.ename,d.dname from emp e,dept dwhere e.deptno=d.deptno and e.deptno<>20 and e.sal>(select max(s

11、al) from emp where deptno=20) ; /*25、得到平均工資大于2000的工作職種 */ select JOB,avg(sal) from emp group by JOBhaving avg(sal)>2000; /*26、分部門得到工資大于2000的所有員工的平均工資,并且平均工資還要大于2500 */ select avg(sal) from empwhere sal>2000group by deptno having avg(sal)>2500;/*27、查找出收入(工資加上獎(jiǎng)金),下級(jí)比上級(jí)還高的員工編號(hào),員工名字,員工收入*/ sele

12、ct empno,ename,sal+nvl(comm,0) from emp e1where sal+nvl(comm,0) >(select sal+nvl(comm,0) from emp where empno=e1.mgr)/*28、查找出不屬于任何部門的員工 */ select * from emp where deptno is null; /*29、查詢出king所在部門的部門號(hào)部門名稱部門人數(shù) */ select d.deptno,d.dname,count(*) from dept d,emp ewhere d.deptno=e.deptno and d.deptno=(select deptno from emp where ename='KING&#

溫馨提示

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

評(píng)論

0/150

提交評(píng)論