题解 | #获得积分最多的人(二)#
获得积分最多的人(二)
https://www.nowcoder.com/practice/b6248d075d2d4213948b2e768080dc92
SELECT t.user_id id,u.name,grade_num FROM ( SELECT user_id,SUM(grade_num) grade_num, DENSE_RANK() over(ORDER BY SUM(grade_num) DESC) rk FROM grade_info WHERE type = 'add' GROUP BY user_id ) t JOIN `user` u ON t.user_id = u.id AND rk = 1 # WHERE rk = 1 ORDER BY t.user_id