题解 | #SQL71 牛客每个人最近的登录日期(六)#
牛客每个人最近的登录日期(六)
http://www.nowcoder.com/practice/572a027e52804c058e1f8b0c5e8a65b4
截止到某日期,用户累计通过的题目数量
关键点:累计-->某个日期及过去日期里的刷题通过数量的加和-->想到自连接判断日期大小
select t1.name as u_n, t2.date, t2.ps_num from user t1 right join ( select p1.user_id, p1.date, sum(p2.number) as ps_num from passing_number p1 left join passing_number p2 on p2.date<=p1.date where p1.user_id = p2.user_id group by p1.user_id,p1.date )t2 on t1.id=t2.user_id order by t2.date asc, t1.name asc