oracle有关查询语句

1. 列出工资在1000到2000之间的所有员工的ENAME,DEPTNO,SAL
select ename,deptno,sal from emp where sal>1000 and sal<2000;
2. 显示DEPT表中的部门号和部门名称,并按部门名称排序。
select deptno,dname from dept order by dname;
3. 显示所有不同的工作类型。
select job from emp;
4.查询名字只有4个字符的所有职工;
select ename from emp where ename like'____';
5. 查询有7902,7566,7788三个MGR号之一的所有职工:
select ename,mgr from emp where mgr=7902 or mgr=7566 or mgr=7788;
6. 列出部门号在10到20之间的所有员工,并按名字的字母排序。
select ename,deptno from emp where deptno>=10 and deptno<=20 order by ename;
7. 列出部门号是20,工作是职员的员工。
select ename,job,deptno from emp where deptno=20 and job='CLERK';
8. 显示名字中包含TH和LL的员工名字。
select * from emp where ename like '%TH%' or ename like '%LL%';
9. 显示所有员工的名字和报酬。
select ename,sal from emp;
10. 显示在1982年中雇佣的员工。
select *from emp where to_char (hiredate,'YYYY') ='1982';
11. 查询每个部门的平均工资、最低工资、最高工资。
select deptno,round(avg(sal)),min(sal),max(sal) from emp group by deptno;
12. 查询出每个部门中工资最高的职工。
select * from emp  where sal in (select max(sal) from emp group by deptno);
13. 查询出每个部门比全部员工平均工资高的职工人数。
select a.deptno,count(*) from emp a,(select deptno,avg(sal) avgsal from emp group by deptno) b where a.deptno=b.deptno and a.sal>b.avgsal group by a.deptno;
14.使用all关键字过滤工资(sal)同时不等于3000、950和800的员工记录。
select * from emp where sal!=all(3000,950,800);
15. 使用LIKE关键字,在emp表中,要显示在1981年雇佣的所有员工的信息
select * from emp where hiredate like'%81%';
16. 在emp表中,查询工作时TURNER的员工姓名,但是不记得TURNER的准确拼写,但还记得它的第1个字符是T,第3个字符是R,第5个字符为E。
select ename from emp where ename like'%T_R_E%';
17. 查询工资大于3000的雇员姓名、工资、雇佣时间及所在部门名称。
select ename,sal,hiredate,dname from emp inner join dept on emp.deptno=dept.deptno where sal>3000;
18. 查询出每个部门比本部门员工平均工资高的职工人数。(5分)
结果显示:“部门号”,“比平均工资高的人数”
select deptno,count(*) from
(select a.deptno,a.ename from emp a,(select avg(sal) avgsal, deptno from emp group by deptno) b
where a.deptno=b.deptno
and a.sal>b.avgsal)
group by deptno;
19.创建一个dept表与emp表相互关联的视图。
CREATE OR REPLACE VIEW emp_view_complex AS
  SELECT D.DNAME,D.LOC,E.EMPNO,E.ENAME
  FROM EMP E,DEPT D
  WHERE E.DEPTNO = D.DEPTNO
20. 通过emp_view_complex视图查询20号部门员工的姓名、工资信息及所在部门名和部门所在位置。
select ename,sal,dname,loc,deptno from emp_view_complex where deptno=20;
drop view emp_view_complex;
drop view emp_view_union;
21. 查询员工的姓名、编号、所在部门、工资(sal)、工资等级,并显示查询结果中的前6条记录(提示:使用伪列rownum
select ename,empno,deptno,sal,grade from emp inner join salgrade on rownum <7;
22. 使用“关联子查询”检索emp表中工资小于同职位平均工资的员工信息。
select * from emp e  
where sal<(select avg(sal) from emp where job=e.job);
23. 从EMP中查询出工资最低的职工。查询结果包括雇员姓名、职务及所在部门名称。
select ename,job,dname from emp inner join dept on emp.deptno=dept.deptno where sal=(select min(sal)from emp);
24. 从EMP中查询出每个部门工资最低的职工。
select * from emp where sal in(select min(sal) from emp group by deptno);
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值