题目链接:点击打开链接
题目大意:略。
解题思路:ROUND 函数,不添加第二个参数,默认为四舍五入到整数;ORDER BY employee_id 前可以不添加表名,因为 SELECT 已经显明了。
AC 代码
SELECT e2.employee_id, e2.name, COUNT(*) reports_count, ROUND(AVG(e1.age)) average_age FROM Employees e1 JOIN Employees e2 ON e1.reports_to = e2.employee_id GROUP BY e1.reports_to HAVING e1.reports_to IS NOT NULL ORDER BY employee_id