select date, sum(rkd) from
(select *, if(rank() over(partition by user_id order by date asc)=1, 1, 0) rkd from login) t
group by date