SELECT seller_id FROM (SELECT seller_id , RANK() OVER(ORDER BY SUM(price) DESC) AS r FROM Sales GROUP BY seller_id) s WHERE s.r=1; 作者:SunnyCCCh 链接:https://leetcode.cn/problems/sales-analysis-i/solutions/868818/partition-by-he-group-by-de-shi-yong-qu-nts8m/ 来源:力扣(LeetCode) 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 SELECT seller_id FROM (SELECT seller_id , RANK() OVER(PARTITION BY seller_id ORDER BY SUM(price) DESC) AS r FROM Sales ) s WHERE s.r=1; 作者:SunnyCCCh 链接:https://leetcode.cn/problems/sales-analysis-i/solutions/868818/partition-by-he-group-by-de-shi-yong-qu-nts8m/ 来源:力扣(LeetCode) 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 --案例1 这个案例等于是将 SELECT SELLER_ID , SUM(PRICE), DENSE_RANK() OVER( ORDER BY SUM(PRICE) DESC ) RN --不分区. 留意最下面有group by ,groupby级别高于开窗函数计算顺序这个是重点. FROM SALES A GROUP BY SELLER_ID --如下结果: | seller_id | sum(price) | dense_rank() over( order by sum(price) desc ) | | --------- | ---------- | ---------------------------------------------- | | 1 | 2800 | 1 | | 3 | 2800 | 1 | | 2 | 800 | 2 |
标签:顺序,SUM,RANK,GROUPBY,price,开窗,seller,id,SELECT From: https://www.cnblogs.com/mengbin0546/p/18412649