MySQL: use CTE & subqueries
\n## Create 1st CTE table to store the number of matching users\nWITH tbl1 AS (\nSELECT COUNT(DISTINCT A.player_id) AS \'counts\'\nFROM Activity A\nJOIN (\nSELE
```\n## Create 1st CTE table to store the number of matching users\nWITH tbl1 AS (\nSELECT COUNT(DISTINCT A.player_id) AS \'counts\'\nFROM Activity A\nJOIN (\nSELECT player_id, MIN(event_date) AS \'first_login\'\nFROM Activity\nGROUP BY player_id) M\nON A.player_id = M.player_id AND DATEDIFF(A.event_date, M.first_login) = 1),\n\n## Create 2nd CTE table to store the total unique users\ntbl2 AS (SELECT COUNT(DISTINCT player_id) AS \'total\' FROM Activity)\n\n## Derive the fraction\nSELECT ROUND(tbl1.counts / tbl2.total, 2) AS \'fraction\' FROM tbl1, tbl2;\n```
[]