SQL 90 ) 获得积分最多的人(二)
获得积分最多的人(二)
http://www.nowcoder.com/questionTerminal/b6248d075d2d4213948b2e768080dc92
使用排序函数rank()over()嵌套sum()over()解决
select u.id, u.name , a.grade from (select user_id , g.grade , rank()over(order by g.grade desc) r_number from (select user_id, sum(grade_num)over(partition by user_id) grade from grade_info)g group by user_id)a join user as u on a.user_id = u.id where a.r_number = 1 order by u.id asc;
SQL 文章被收录于专栏
SQL