MySQL Solution faster 92.13% CTE, Explanation
Explanation:\nThe first cte adds a day to the event date essentially selecting the ext day for each player starting from the earliest date. It is important to u
Explanation:\nThe first cte adds a day to the event date essentially selecting the ext day for each player starting from the earliest date. It is important to use min function or you will get the answer wrong.\n\nThe final sql statement joins the previous cte with the activity table. By joining on tomorrow column and player id you limit the result to only show matches from the cte. from there you do distinct count divided by distinct count of all players in the select table to get your final solution.\n\n```\nwith cte1 as (\n    select player_id, DATE_ADD(min(event_date), INTERVAL 1 DAY) tomorrow\n    from Activity\n    group by player_id)\n\nselect round(count(distinct a.player_id)/(select count(distinct player_id) from Activity),2) fraction\nfrom Activity a\njoin cte1 c on c.player_id=a.player_id and c.tomorrow=a.event_date\n```
['MySQL']