select empid
from (select empid, avg(hours) as avghours
from workload
group by empid) c
where c.avghours>= (select max(avghours)
from (select empid, avg(hours) as avghours
from workload
group by empid))
用了两次相同的子查询,
谁能用简洁的一条sql搞定呢,麻烦献上一条哦,感谢!!!
...全文
16398打赏收藏
用简洁的sql 查询出平均值的最大值
表workload(empid,workdate,hours),用一条sql查询出平均每天工作小时数最多的员工id,试了很多,都感觉写的很累赘, select empid from (select empid, avg(hours) as avghours from workload group by empid) c where c.avghours>= (select max(avghours) from (select empid, avg(hours) as avghours from