题解 | #实习广场投递简历分析(三)#

获得积分最多的人(三)

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


SELECT
t.id,t.name,t.num
FROM
    (
        SELECT
         a.id,a.`name`,a.num,DENSE_RANK() OVER(ORDER BY a.num DESC) number
         FROM
        (
        SELECT
    DISTINCT(g.user_id) id,u.`name`,SUM(g.grade_num) over(PARTITION BY g.user_id) AS num
    FROM
    (
        SELECT user_id,
            CASE type
            WHEN 'add' THEN
                grade_num
            ELSE
                -(grade_num)
            END grade_num,type
        FROM
        grade_info
    ) g,`user` u
    WHERE
    g.user_id = u.id
    ORDER BY
    num DESC
    )a
)t
WHERE
t.number = 1
ORDER BY
t.id 
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务