题解 | #case when 的使用#
牛客每个人最近的登录日期(四)
https://www.nowcoder.com/practice/e524dc7450234395aa21c75303a42b0a
select date, count(distinct case when (user_id, date) in ( select user_id, min(date) from login group by user_id ) then user_id else null end) new from login group by date order by date
case when 可以在count中做条件语句,distinct 防止在同一天登录了多次,导致多条记录重复计数。