oracle 数据库默认的scott.emp表的各种查询

1、列出至少有一个员工的所有部门。
select EMPNO,ENAME,JOB,MGR HIREDATE,SAL,COMM,DEPTNO from scott.emp where ename in('ALLEN','BLAKE');
  2、列出薪金比“SMITH”多的所有员工。
3、列出所有员工的姓名及其直接上级的姓名。
select ENAME from scott.emp;
  4、列出受雇日期早于其直接上级的所有员工。
  5、列出部门名称和这些部门的员工信息,同时列出那些没有员工的部门
  6、列出所有“CLERK”(办事员)的姓名及其部门名称。
  7、列出最低薪金大于1500的各种工作。
  8、列出在部门“SALES”(销售部)工作的员工的姓名,假定不知道销售部的部门编号。
  9、列出薪金高于公司平均薪金的所有员工。
  10、列出与“SCOTT”从事相同工作的所有员工。
  11、列出薪金等于部门30中员工的薪金的所有员工的姓名和薪金。
  12、列出薪金高于在部门30工作的所有员工的薪金的员工姓名和薪金。
  13、列出在每个部门工作的员工数量、平均工资和平均服务期限。
  14、列出所有员工的姓名、部门名称和工资。
  15、列出所有部门的详细信息和部门人数。
  16、列出各种工作的最低工资。
  17、列出各个部门的MANAGER(经理)的最低薪金。

表是oracle自带的emp表.麻烦各位帮忙弄出来。最好代码是小写的。容易区别。谢谢!!

--1
select deptno, count(*) from EMP group by DEPTNO having count(*) >1;

--2
select * from emp where sal > (select sal from emp where ename = 'SMITH');

--3
select e0.ENAME, e1.ename from emp e0, emp e1 where e0.MGR = e1.empno;

--4
select e0.*, e1.* from emp e0, emp e1 where e0.mgr = e1.empno(+) and e0.hiredate < e1.hiredate;

--5
select d.dname, e.* from dept d, emp e where d.deptno = e.deptno(+);

--6
select e.ename, d.dname from emp e join dept d on e.deptno = d.deptno where job = 'CLERK';

--7
select job from emp group by job having min(sal) > 1500;

--8
select e.ename from emp e, dept d where d.dname = 'SALES' and e.deptno(+) = d.deptno;

--9
select * from emp where sal > (select avg(sal) from emp); 

--10
select * from emp where job = (select job from emp where ename = 'SCOTT');

--11
select * from emp where sal in (select sal from emp where deptno = 30);

--12
select * from emp where sal > all (select sal from emp where deptno = 30);

--13
select count(empno) 人数, avg(sal) 平均工资, avg(EXTRACT(year FROM sysdate) - EXTRACT(year FROM emp.hiredate)) 平均雇佣期限 from dual, emp group by deptno;

--14
select e.ename, d.dname, e.sal from emp e, dept d  where e.deptno = d.deptno(+);

--15
select d.*, t.count from dept d, (select deptno, count(empno) count from emp group by deptno) t where d.deptno = t.deptno(+);

--16
select job, min(sal) from emp group by job;

--17
select deptno, min(sal) from emp where job = 'MANAGER' group by deptno;

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网