Oracle 查询练习

emp 员工表(empno 员工号/ename 员工姓名/job 工作/mgr 上级编号/hiredate 受雇日期/sal 薪金/comm 佣金/deptno 部门编号)
dept 部门表(deptno 部门编号/dname 部门名称/loc 地点)
工资 = 薪金 + 佣金
1.列出至少有一个员工的所有部门。

select dname from dept where deptno in(
select deptno from emp);

2.列出薪金比“SMITH”多的所有员工。

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

3.列出所有员工的姓名及其直接上级的姓名。、

select a.ename,(
select ename from emp b where b.empno=a.mgr) as bossname from emp a;

4.列出受雇日期早于其直接上级的所有员工。

select a.ename from emp a where a.hiredate<(
select hiredate from emp b where b.empno=a.mgr);

6.列出所有“CLERK”(办事员)的姓名及其部门名称。

select a.ename,b.dname from emp a join dept b
on a.deptno=b.deptno and a.job='CLERK';

7.列出最低薪金大于 1500 的各种工作。

select distinct job as HighSalJob from emp group by job having min(sal)>1500;

8.列出在部门“SALES”(销售部)工作的员工的姓名,假定不知道销售部的部门编号。

select ename from emp where deptno=(
select deptno from dept where dname='SALES');

9.列出薪金高于公司平均薪金的所有员工。

select ename from emp where sal>(
select avg(sal) from emp);

10.列出与“SCOTT”从事相同工作的所有员工。

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

11.列出薪金等于部门 30 中员工的薪金的所有员工的姓名和薪金。

select a.ename,a.sal from emp a where a.sal in (
select b.sal from emp b where b.deptno=30) and a.deptno<>30;

12.列出薪金高于在部门 30 工作的所有员工的薪金的员工姓名和薪金。

select ename,sal from emp where sal>(
select max(sal) from emp where deptno=30);

13.列出在每个部门工作的员工数量、平均工资和平均服务期限。

select
(select b.dname from dept b where a.deptno=b.deptno) as deptname , count(deptno) as deptcount,
avg(sal) as deptavgsal
from emp a group by deptno;

14.列出所有员工的姓名、部门名称和工资。

select
a.ename,
(select b.dname from dept b where b.deptno=a.deptno) as deptname,
sal
from emp a;

15.列出所有部门的详细信息和部门人数。

select
a.deptno,
a.dname,
a.loc,
(select count(deptno) from emp b where b.deptno=a.deptno group by b.deptno) as deptcount
from dept a;

16.列出各种工作的最低工资。

select job,avg(sal) from emp group by job;

17.列出各个部门的 MANAGER(经理)的最低薪金。

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

18.列出所有员工的年工资,按年薪从低到高排序。

select ename,(sal+nvl(comm,0))*12 as salpersal from emp order by salpersal;
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值