ex:查询大于公司平均工资的员工姓名:性能
select avg(sal) from emp; /* avg(sal)=2000 */ select * from emp where sal >= 2000; /* 将上面的语句合并 */ select * from emp where sal >= (select avg(sal) from emp);
ex:查询出工资比anthony还要高的所有雇员信息:spa
select sal from emp where name='anthony'; /* anthony的工资为10000 */ select * from emp where sal >= 10000; /* 将上面的语句合并 */ select * from emp where sal >= (select sal from emp where name='anthony');
根据子查询的结果来划分的code
与返回列表中的任意一个值相等
ex:查询工资等于部门经理的员工信息图片
select sal from emp where job ='manager'; /* 先查询部门经理的工资 */
与返回的任意一个值比较it
与返回的值每个值比较io
select d.deptno,d.dname,temp.c,temp.a from dept d join (select deptno,count(empno) c,avg(sal) a from emp group by deptno) temp on using(deptno);
join用于把表横向链接,union/union all用于把表纵向链接
注意:class
-列也必须拥有兼容的数据类型select
select empno,ename,dname from emp left join dept using(deptno) union select empno,ename,dname from emp right join dept using(deptno);