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

获得积分最多的人(三)

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

select 
    t1.id  as 'id'
    ,u.name  as 'name'
    ,t1.grade as 'grade_num'
from
(
select 
    t0.user_id id
    ,t0.grade  grade
    ,dense_rank()over(order by t0.grade desc) r
from 
(
select 
   a.user_id user_id
   ,a.add-ifnull(b.red,0) grade
from

(
select 
    user_id 
    ,sum(grade_num) as 'add'
from 
    grade_info 
where 
    type='add'
group by 
    user_id 
) a
left join

(
select 
    user_id 
    ,sum(grade_num) as 'red'
from 
    grade_info 
where 
    type='reduce'
group by 
    user_id 
) b
on a.user_id=b.user_id
) t0
) t1 
left join 
    user u 
on 
    t1.id=u.id
where 
    t1.r=1
order by 
    t1.id

全部评论

相关推荐

牛客101244697号:这个衣服和发型不去投偶像练习生?
点赞 评论 收藏
分享
爱看电影的杨桃allin春招:我感觉你在炫耀
点赞 评论 收藏
分享
海康威视 软开岗 15k15
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务