时间:2021-07-01 10:21:17 帮助过:2人阅读
题2:获取年龄最大的员工(可能不止一个)
select * from t_person where age = (select max(age) from t_person);
题3:获取每个部门年龄最大的员工
SELECT * FROM t_person p JOIN ( SELECT max(age) max_age, department_id FROM t_person GROUP BY department_id ) t ON p.department_id = t.department_id AND p.age = t.max_age;
题4:获取每个部门大于平均年龄的员工
SELECT * FROM t_person p JOIN ( SELECT avg(age) avg_age, department_id FROM t_person GROUP BY department_id ) t ON p.department_id = t.department_id AND p.age >= t.avg_age;
sql 练习题
标签:_id sel avg rom where pre art 获取 and