- 列出每个部门年龄最大的员工姓名,部门名等信息
- 列出每个部门的员工总收入
- 列出员工总收入大于8000的部门号,部门名称信息
- 有哪个部门还有员工未入职
- 按部门号大小,入职时间由早到晚排序员工信息表
1.sqlite> SELECT e.e_name, MAX(e.e_age), d.name FROM employee e
...> INNER JOIN dept d ON e.e_dept_id=d.id
...> GROUP BY e.e_dept_id;
2.sqlite> SELECT SUM(e.e_salary), d.name FROM employee e
...> INNER JOIN dept d ON e.e_dept_id=d.id
...> GROUP BY e.e_dept_id;
3.sqlite> SELECT e.e_dept_id, d.name FROM employee e
...> INNER JOIN dept d ON e.e_dept_id=d.id
...> GROUP BY e.e_dept_id
...> HAVING SUM(e.e_salary)>8000;
4.sqlite> SELECT d.id, d.name FROM dept d
...> WHERE d.id NOT IN
...> (SELECT e.e_dept_id FROM employee e);
5.sqlite> SELECT * FROM employee e
...> ORDER BY e.e_dept_id ASC, e_time ASC;
- 查询每个部门及部门平均工资并按薪资由高到低排序
- 查询部门及其最高薪资员工ID
1.sqlite> SELECT d.dept, AVG(s.salary) FROM dept d
...> INNER JOIN employee e ON d.name=e.name
...> INNER JOIN salary s ON e.id=s.id
...> GROUP BY d.dept
...> ORDER BY AVG(s.salary) DESC;
2.sqlite> SELECT d.dept, s.id, e.name, MAX(s.salary) FROM dept d
...> INNER JOIN employee e ON d.name=e.name
...> INNER JOIN salary s ON e.id=s.id
...> GROUP BY d.dept;