-1
下面的查詢: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點的數據...什麼是該解決方案?
下面的查詢: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點的數據...什麼是該解決方案?
你需要一個子查詢:
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;
(當然,除非你正在使用Teradata和可以使用qualify
條款。)
WHERE過濾器聚合之前,您需要具有後對結果進行過濾聚合。 –