select a.date,(case when c.next_u is null then 0.000
else round(c.next_u/b.new_u,3) end) p
from (select distinct date from login) a
left join
(select date,count(*) new_u
from login
where (user_id,date) in (select user_id,min(date) date from login
group by user_id)
group by date) b
on a.date = b.date
left join
(select date,count(*) next_u
from login
where (user_id,date) in (select user_id,
date_add(min(date),interval 1 day)
from login group by user_id)
group by date) c
on date_add(b.date,interval 1 day) = c.date
order by a.date;
else round(c.next_u/b.new_u,3) end) p
from (select distinct date from login) a
left join
(select date,count(*) new_u
from login
where (user_id,date) in (select user_id,min(date) date from login
group by user_id)
group by date) b
on a.date = b.date
left join
(select date,count(*) next_u
from login
where (user_id,date) in (select user_id,
date_add(min(date),interval 1 day)
from login group by user_id)
group by date) c
on date_add(b.date,interval 1 day) = c.date
order by a.date;