要求:
1.找出销售部门中年纪最大的员工的姓名
2.求财务部门最低工资的员工姓名
3.列出每个部门收入总和高于9000的部门名称
4.求工资在7500到8500元之间,年龄最大的人的姓名及部门
5.找出销售部门收入最低的员工入职时间
6.财务部门收入超过2000元的员工姓名
7.列出每个部门的平均收入及部门名称
8.IT技术部入职员工的员工号
9.财务部门的收入总和;
10.找出哪个部门还没有员工入职;
11.列出部门员工收入大于7000的部门编号,部门名称;
12.列出每一个部门的员工总收入及部门名称;
13.列出每一个部门中年纪最大的员工姓名,部门名称;
14.求李四的收入及部门名称
15.列出每个部门中收入最高的员工姓名,部门名称,收入,并按照收入降序
1、mysql> select name from emp,dept
-> where emp.dept2=dept.dept1
-> and age>all(select age from emp where emp.dept2=102);
2、mysql> select name from emp,dept
-> where emp.dept2=dept.dept1
-> and incoming in (select min(incoming) from emp
-> group by dept.dept_name
-> having dept_name='财务');
3、mysql> select dept_name from emp left join dept
-> on emp.dept2=dept.dept1
-> group by dept_name
-> having sum(incoming)>9000;
4、mysql> select name,dept_name from emp,dept
-> where emp.dept2=dept.dept1
-> and age=(select max(age) from emp where incoming between 7500 and 8500);
5、mysql> select worktime_start from emp,dept
-> where emp.dept2=dept.dept1
-> and incoming =(select min(incoming) from emp left join dept on emp.dept2=dept.dept1
-> where dept_name='销售');
6、mysql> select name from emp left join dept
-> on emp.dept2=dept.dept1
-> where incoming>2000 and dept_name='财务';
7、mysql> select avg(incoming),dept_name from emp left join dept
-> on emp.dept2=dept.dept1
-> group by dept_name;
8、mysql> select sid from emp left join dept
-> on emp.dept2=dept.dept1
-> where dept_name='IT技术';
9、mysql> select sum(incoming) from emp left join dept
-> on emp.dept2=dept.dept1
-> where dept_name='财务';
10、mysql> select distinct dept_name from emp,dept
-> where dept.dept1 not in(select dept2 from emp);
11、mysql> select dept1,dept_name from emp,dept
-> where dept.dept1=emp.dept2
-> and incoming>7000;
12、mysql> select sum,dept_name from dept left join
-> (select sum(incoming) sum,dept2 from emp group by dept2) e
-> on dept.dept1=e.dept2;
13、mysql> select name,dept_name from dept left join emp
-> on dept.dept1=emp.dept2
-> where age in(select max(age) from emp group by dept2);
14、mysql> select incoming,dept_name from emp,dept
-> where dept.dept1=emp.dept2
-> and name='李四';
15、mysql> select name,dept_name,incoming from emp join dept
-> on dept.dept1=emp.dept2
-> where(dept2,incoming)
-> in (select max(incoming),dept2 from emp group by dept2,dept.dept_name)
-> order by incoming desc;