oracle数据库scott用户下的EMP表、DEPT表的各种查询

<span style="font-size:18px;"><strong>--连接查询:</strong></span>
--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、列出所有“CLERK”(办事员)的姓名及其部门名称。
select e.ename, d.dname from emp e join dept d on e.deptno = d.deptno where job = 'CLERK';

--8、列出在部门“SALES”(销售部)工作的员工的姓名,假定不知道销售部的部门编号。
select e.ename from emp e, dept d where d.dname = 'SALES' and e.deptno(+) = d.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 de

ptno) t where d.deptno = t.deptno(+);


<span style="font-size:18px;"><strong>--分组查询:</strong></span>
--1、列出至少有一个员工的所有部门。
select deptno, count(*) from EMP group by DEPTNO having count(*) > 1;


--7、列出最低薪金大于1500的各种工作。
select job from emp group by job having min(sal) > 1500;

--13、列出在每个部门工作的员工数量、平均工资和平均服务期限。
select count(empno) 人数, avg(sal) 平均工资, avg(EXTRACT(year FROM sysdate) - EXTRACT(year FROM emp.hiredate)) 平均雇佣期限 from dual, emp group by deptno;

--16、列出各种工作的最低工资。
select job, min(sal) from emp group by job;

--17、列出各个部门的MANAGER(经理)的最低薪金。
select deptno, min(sal) from emp where job = 'MANAGER' group by deptno;


<span style="font-size:18px;"><strong>--子查询:</strong></span>
--2、列出薪金比“SMITH”多的所有员工。
select * from emp where sal > (select sal from emp where ename = 'SMITH');

--9、列出薪金高于公司平均薪金的所有员工。
select * from emp where sal > (select avg(sal) from emp); 

--10、列出与“SCOTT”从事相同工作的所有员工。
select * from emp where job = (select job from emp where ename = 'SCOTT');

--11、列出薪金等于部门30中员工的薪金的所有员工的姓名和薪金。
select * from emp where sal in (select sal from emp where deptno = 30);

--12、列出薪金高于在部门30工作的所有员工的薪金的员工姓名和薪金。
select * from emp where sal > all (select sal from emp where deptno = 30);

  • 4
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值