列出在项目中累计工作时间最多的员工姓名及其所在部门名称。还要列出他/她的累计工作时间。
SELECT e.name, e.empid, e.did, e_hrs.emphours
FROM employee e
INNER JOIN
(select empid, sum(hours) as emphours
from workon
group by empid) e_hrs
ON e.empid= e_hrs.empid
我该如何做最多的累积时间?
通过添加order by,您可以限制为1:
SELECT e.name, e.empid, e.did, e_hrs.emphours
FROM employee e
INNER JOIN
(select empid, sum(hours) as emphours
from workon
group by empid) e_hrs
ON e.empid= e_hrs.empid
Order by e_hrs.emphours desc
limit 1;