您的位置:首页 > 数据库 > Oracle

Oracle学习笔记20150818一些常见查询语句

2015-08-17 08:44 519 查看
(1)单行子查询用"=",多行子查询用"in".

(2)all的用法select * from emp where  sal> all(select sal from where deptno=30).

(3)与all同样用法的还有any,只需注意其代表的意义.

(4)多列子查询可以用这种方法select * from emp where(deptno,job)=(select deptno,job from emp where ename='SMITH');

(5)null前面只能加is与is not;

(6)把前面的查询结果当做一个临时表对待

select t2.ename,t2.sal,myavg,t2 deptno from emp t2,(select avg(sal) myavg,deptno from emp group by deptno)t1 where t2.deptno=t1.deptno and t2.sal>t1.myavg;

查询每个大于本部门平均工资的员工.

(7)分析 select t2.ename,sal,t1.myavg,t2.deptno from emp t2,(select avg(sal) myavg,deptno from emp group by deptno) t1 where t2.deptno=t1.deptno and t2.sal>t1.myavg;

(8) select * from emp,(select max(sal) sal,deptno from emp group by deptno) t1 where emp.deptno=t1.deptno and emp.sal=t1.sal;

 查询每个部门工资最高的人的信息

 (9)select dept.dname,t1.deptno,t1.coun from dept,(select deptno,count(*) coun from emp group by deptno) t1 where dept.deptno=t1.deptno;

 查询每个部门信息以及相应部门雇员总数
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: