我必须得到一份所有工作职位的清单以及在那里工作的人的工资总和......
我用这个得到了:
SELECT j.job_title, SUM(e.salary)
FROM jobs j LEFT JOIN employees e ON e.job_id = j.job_id
GROUP BY j.job_title;
好的,但现在我必须得到相同的清单,但还要考虑到城市......
它不起作用...:/
SELECT j.job_title, SUM(e.salary), d.department_id, l.city
FROM departments d LEFT JOIN employees e ON e.department_id = d.department_id LEFT JOIN locations l
ON l.location_id = d.location_id LEFT JOIN jobs j ON e.job_id = j.job_id
GROUP BY l.city;
为什么会这样?