题解 | #获得积分最多的人(三)#

获得积分最多的人(三)

https://www.nowcoder.com/practice/d2b7e2a305a7499fb310dc82a43820e8

WITH total_grade AS (
    SELECT user_id, SUM(IF(type='add', grade_num, -grade_num)) AS grade
    FROM grade_info
    GROUP BY user_id
),
max_grade AS (
    SELECT MAX(grade)
    FROM total_grade
)
SELECT u.id, u.name, t.grade AS grade_num
FROM user AS u
INNER JOIN total_grade AS t
ON u.id = t.user_id
WHERE t.grade
IN (SELECT * FROM max_grade);

全部评论

相关推荐

10-25 00:32
香梨想要offer:感觉考研以后好好学 后面能乱杀,目前这简历有点难
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务