MSSQL : Simple and faster than 98.07% (USING CTE)
--Step1: finding the minimum event date for each player in a CTE\n\nWITH MinDate AS (SELECT player_id, MIN(event_date) minDt\nFROM Activity\nGROUP BY player_id)
`--Step1: finding the minimum event date for each player in a CTE`\n```\nWITH MinDate AS (SELECT player_id, MIN(event_date) minDt\nFROM Activity\nGROUP BY player_id)\n```\n\n`--Step2: Join CTE and Activity table based on player id and date difference. And if date difference between event date and minimum event date (for each player ID) is one day then count the number of players and divide it by total number of players`\n\n```\nSELECT ROUND(COUNT(a.player_id)*1.0/(SELECT COUNT(DISTINCT player_id) FROM ACtivity),2) fraction  \nFROM Activity a, MinDate md\nWHERE DATEDIFF(day, md.minDt, event_date) = 1\nAND a.player_id = md.player_id\n```
['MS SQL Server']