与最高薪资发现相关的SQL查询

时间:2017-07-27 17:50:30

标签: sql

以下查询:

SELECT ROW_NUMBER() OVER(ORDER BY sum(salary) DESC) as num,id, sum(salary) as salary
FROM person
GROUP BY id
where num=3;

where条件下给我一个错误,我希望获得第3行数据......对此有什么解决方法?

1 个答案:

答案 0 :(得分:0)

你需要一个子查询:

Finish

(好吧,除非您使用Teradata并且可以使用select p.* from (select ROW_NUMBER() OVER (ORDER BY sum(salary) DESC) as num, id, sum(salary) as salary from person group by id ) p where num = 3; 子句。)