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搞定呢,麻烦献上一条哦,感谢!!! ------解决方案--------------------
正解,
分析函数,改成rank更好吧,可以查询出并列的。 ------解决方案-------------------- SELECT empid
FROM (SELECT AVG(hours), empid
FROM workload
GROUP BY empid
ORDER BY AVG(hours) DESC)
WHERE ROWNUM = 1