题解 | #牛客每个人最近的登录日期(二)#
牛客每个人最近的登录日期(二)
http://www.nowcoder.com/practice/7cc3c814329546e89e71bb45c805c9ad
三表连接对日期排名,取最大
select u_n,c_n, 最近日期 from ( select c.name as u_n,b.name as c_n,max(t.date) as 最近日期 ,dense_rank() over(partition by c.name order by max(date) desc) as 排名 from login as t join user as c on t.user_id=c.id join client as b on b.id=t.client_id group by c.name,b.name ) as f where 排名=1 order by u_n ;