select date, count(distinct case when datediff(date,first_day)=0 then user_id end) as new from ( select user_id, date, min(date) over(partition by user_id ) as first_day from login ) t group by date;