我的查询得到每个年级的每个部门的员工数。
select dept , grade , count(1) CNT
from mytable
group by dept , grade
order by dept , cnt desc;
现在我需要获得每个部门的最高分数。
输出应该是
dept grades MAX(count)
我该怎么做?
由于
答案 0 :(得分:0)
执行此操作的最佳方法是使用row_number()
功能:
select dept, grade, cnt
from (select dept, grade, count(*) as cnt,
row_number() over (partition by dept order by count(*) desc) as seqnum
from mytable t
group by dept, grade
) t
where seqnum = 1