久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

Oracle復(fù)雜查詢

 wghbeyond 2012-07-16

1:列出所有員工的姓名,,部門名稱,,和工資

select a1.ename,a1.sal,a2.dname from emp a1,dept a2 where a1.deptno = a2.deptno;

2:列出所有部門的詳細(xì)信息和部門人數(shù)

select a2.deptno,a2.dname,a2.loc,count(a1.empno) from emp a1,dept a2 where a1.deptno(+) = a2.deptno group by a2.deptno,a2.dname,a2.loc;

3:列出所有員工的年工資,,所在部門名稱,,按年薪升序排列

select a1.sal*12 ,a2.dname from emp a1,dept a2 where a1.deptno = a2.deptno order by a1.sal*12;

4:查出每個員工的上級主管及所在部門名稱,,并要求這些主管的薪水超過3000

select employee.ename,boss.ename ,a1.dname from emp employee,emp boss,dept a1 where employee.mgr = boss.empno and boss.deptno = a1.deptno and boss.sal >3000;

5:求出部門名稱中帶’S’字符的部門員工的工資合計(jì),,部門人數(shù)

SELECT d.deptno,NVL(SUM(sal),0),COUNT(empno)FROM emp e,dept d WHERE e.deptno(+)=d.deptno AND d.dname LIKE '%S%' GROUP BY d.deptno ;

6:列出部門名稱和這些部門的員工信息(數(shù)量,,平均工資),,同時列出那些沒有員工的部門

select d.dname,avg(e.sal),count(e.empno) from emp e,dept d where e.deptno(+)=d.deptno group by d.dname;

7:列出在部門”SALES”工作的員工姓名,,基本工資,雇用日期,,部門名稱,,假定不知道銷售部的部門編號

select a1.ename,a1.sal,a1.hiredate,a2.dname from emp a1,dept a2 where a1.deptno = a2.deptno and a2.dname = 'SALES';

8:列出公司各個工資等級雇員的數(shù)量,平均工資

select grade,count(*),avg(sal) from emp, salgrade where sal between losal and hisal group by grade;

9:列出薪水高于在部門30工作的所有員工的薪金的員工姓名和薪金,,部門名稱

select a1.ename,a1.sal,a2.dname from emp a1, dept a2 where a1.deptno = a2.deptno and sal > all(select sal from emp where deptno = 30);

10:列出受雇日期早于直接上級的所有員工的編號,,姓名,部門名稱,,部門位置,,部門人數(shù)

SELECT e.empno,e.ename,d.dname,d.loc,temp.count

FROM emp e,emp m,dept d,(

     SELECT deptno dno, COUNT(empno) count

     FROM emp

     GROUP BY deptno) temp

WHERE e.mgr = m.empno(+) AND e.hiredate < m.hiredate

AND e.deptno = d.deptno

AND e.deptno = temp.dno;

11:列出所有“clerk”的姓名及其部門名稱,部門人數(shù),,工資等級

SELECT e.ename , d.dname ,temp.count,s.grade

FROM emp e, dept d,(

     SELECT deptno dno,COUNT(empno) count

     FROM emp

     GROUP BY deptno) temp,salgrade s

WHERE job='CLERK'

AND e.deptno = d.deptno

AND d.deptno = temp.dno

AND e.sal BETWEEN s.losal AND s.hisal;

12:列出最低薪金大于1500的各種工作及從事此工作的全部雇員人數(shù)及所在部門名稱,,位置,平均工資

SELECT t.job,t.count,d.dname,e.ename,reg.avg

FROM dept d,(

     SELECT e.job,COUNT(e.empno) count

     FROM emp e

     GROUP BY e.job

     HAVING MIN(e.sal)>1500

)t,emp e,(

       SELECT deptno dno,AVG(sal) avg

       FROM emp

       GROUP BY deptno

)reg

WHERE e.deptno = d.deptno AND e.job = t.job

AND e.deptno = reg.dno;

13:列出薪金高于公司平均薪金的所有員工,,所在部門,,上級領(lǐng)導(dǎo),公司的工資等級

select a1.ename,a2.dname,a1.mgr,a3.grade from emp a1,dept a2,salgrade a3,(select avg(sal) mysal from emp) a4 where a1.deptno = a2.deptno and sal between a3.losal and a3.hisal and a1.sal > a4.mysal;

14:列出與SCOTT從事相同工作的所有員工及部門名稱,,部門人數(shù)

SELECT e.empno,e.ename,e.job,d.dname,temp.count FROM emp e,dept d,(SELECT deptno dno,COUNT(empno) count FROM emp GROUP BY deptno) temp

WHERE e.job=(SELECT job FROM emp WHERE ename='SCOTT') AND e.ename<>'SCOTT' AND e.deptno=d.deptno AND temp.dno=e.deptno;

15:列出在每個部門工作的員工數(shù)量,,平均工資,和平均服務(wù)年限

SELECT d.dname,count(e.empno),avg(e.sal),round(avg(sysdate-e.hiredate)/365) from emp e,dept d where e.deptno(+)=d.deptno GROUP BY d.dname;

16:列出各種工作的最低工資及此雇員姓名

select a1.ename,a1.job,a1.sal from emp a1,(select job,min(sal) min_sal from emp group by job) a2 where a1.job=a2.job and a1.sal=a2.min_sal;

17:列出各個部門的MANAGER的最低薪金,,姓名,,部門名稱,部門人數(shù)

select e.sal,e.ename,d.dname, count from(select job,min(sal) sal,ename,deptno from emp where job='MANAGER'GROUP BY job,ename,deptno) e,

(select d.deptno,d.dname,count(e.empno) count fromemp e,dept d wheree.deptno=d.deptno GROUP BY d.deptno,d.dname) d

where e.deptno=d.deptno;

Oracle分頁(根據(jù)ROWNUM分頁)

select * from (select a1.*,rownum rn from (select ename,sal from emp order by sal) a1 where rownum<=10) where rn >=6;

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請點(diǎn)擊一鍵舉報(bào),。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多