SOLUTION WITH LEAD() OVER() ( MySQL )
Intuition\r\n Describe your first thoughts on how to solve this problem. \r\n\r\n# Approach\r\n Describe your approach to solving the problem. \r\n\r\n# Complex
# Intuition\r\n<!-- Describe your first thoughts on how to solve this problem. -->\r\n\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\n\r\n# Complexity\r\n- Time complexity:\r\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\r\n\r\n- Space complexity:\r\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\r\n\r\n# Code\r\n```\r\n# Write your MySQL query statement below\r\n\r\n\r\nWITH CTE AS (SELECT\r\n\tplayer_id,\r\n\tevent_date,\r\n\tCASE WHEN\r\n\t\tlead(event_date) OVER(partition by player_id order by player_id,event_date) = \r\n\t\tDATE_ADD(event_date ,INTERVAL 1 DAY) \r\n\t\tTHEN 1 ELSE 0 END Isnext\r\nFROM \r\n\tActivity\r\n)\r\n\r\nSELECT\r\n\tROUND(  COUNT(DISTINCT C.player_id) \r\n  / (SELECT COUNT(DISTINCT player_id) FROM Activity) \r\n  ,\r\n   2) fraction\r\nFROM\r\n\tCTE C\r\nINNER JOIN\r\n\t(\r\n\t\tSELECT\t\r\n\t\t\tplayer_id,\r\n\t\t\tmin(event_date) mindate\r\n\t\tFROM\r\n\t\t\tActivity\r\n\t\tGROUP BY\r\n\t\t\tplayer_id\r\n\t)sub ON C.player_id = sub.player_id\r\n\tANd\r\n\t\tC.event_date = sub.mindate\r\nWHERE\r\n\tIsnext > 0\r\n```
['MySQL']