题解 | #查找在职员工自入职以来的薪水涨幅情况#

牛客每个人最近的登录日期(五)

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

纪念一下想了几个小时才做对的答案。。。。。

select date,
case when count(ddd.mindate) = 0 then round(0,3)
else round(count(ddd.nextdate)*1.0/count(ddd.mindate),3)
end p
from login l
left join
(select min(dd.date_old) mindate, dd.date_new nextdate, dd.user_id from
(select d1.user_id, d1.date date_old, d2.date date_new from login d1
left join login d2
on d1.user_id = d2.user_id and date(d1.date,'+1 day') = d2.date) dd
group by dd.user_id) ddd
on date = ddd.mindate and l.user_id = ddd.user_id
group by date
order by date
;
全部评论

相关推荐

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