题解 | #获得积分最多的人(一)#
获得积分最多的人(一)
http://www.nowcoder.com/practice/1bfe3870034e4efeb4b4aa6711316c3b
分组对user_id求和,然后取出最高位即可
SELECT u.name, t.grade_sum FROM (SELECT user_id,SUM(grade_num) "grade_sum" FROM grade_info WHERE TYPE = "add" GROUP BY user_id)t LEFT JOIN `user` u ON t.user_id = u.id ORDER BY t.grade_sum DESC LIMIT 0,1