NullPointerException
我编写此查询以查找最大金额
create table dept
(
did char(12) primary key,
budget float,
managerId int foreign key references emp
)
但是我想找到可以处理最大预算的managerId。
答案 0 :(得分:1)
select top 1 sum(budget), managerId
from dept
group by managerId
order by sum(budget) desc
答案 1 :(得分:1)
只需选择sum(budget)
等于max
的这些行。使用子查询来计算max
SELECT managerId
FROM dept
GROUP BY managerId
HAVING sum( budget ) = (
SELECT MAX(aa) as max
FROM (
SELECT SUM(budget) AS aa FROM dept GROUP BY managerId
) dept
)