标签:avg where select 部门 from 工资 工作 嵌套 孙悟空
1. 查询工资高于1号部门平均工资的员工信息
select avg(sal) from emp where deptno=1;
select * from emp where sal>2330;
合并上面两条SQL select * from emp where sal>(select avg(sal) from emp where deptno=1);
2. 查询工资最高的员工信息
select max(sal) from emp;
select * from emp where sal=(select max(sal) from emp);
3. 查询工资高于2号部门最低工资的员工信息
select * from emp where sal>(select min(sal) from emp where deptno=2);
4. 查询和孙悟空相同工作的其它员工信息
select job from emp where ename="XXX";
select * from emp where job=(select job from emp where ename="孙悟空") and ename!="XXX";
5. 查询拿最低工资员工的同事们的信息(同事指相同部门)
得到最低工资
select min(sal) from emp;
得到最低工资的员工的部门编号
select deptno from emp where sal=(select min(sal) from emp);
得到上面部门编号的员工 并且排除掉最低工资的员工
select * from emp where deptno=(select deptno from emp where sal=(select min(sal) from emp)) and sal!=(select min(sal) from emp);
6. 查询白骨精的部门信息(需要用到部门表dept)
select deptno from emp where ename="白骨精";
select * from dept where deptno=(select deptno from emp where ename="白骨精");
标签:avg where select 部门 from 工资 工作 嵌套 孙悟空
原文地址:https://www.cnblogs.com/star-Java/p/13976595.html