题解 | #牛客每个人最近的登录日期(四)#
牛客每个人最近的登录日期(四)
http://www.nowcoder.com/practice/e524dc7450234395aa21c75303a42b0a
之前没有加user_id结果错误,运行没有问题,觉得case when语句没有用到user_id就省略了,这个因为Mysql还是比较松,正确的做法是group by 后面的列,select后面要有该列
select date,
sum(
case when (user_id,date) in (
select user_id,min(date)
from login
group by user_id
)
then 1
else 0
end
)
from login
group by date
order by date;