Easy Solution with steps in details and optimum runtime
Please Upvote my solution, if you find it helpful :)\n# Problem\nyou need to count the number of players that logged in for at least two consecutive days starti
### ***Please Upvote my solution, if you find it helpful :)***\n# Problem\nyou need to count the number of players that logged in for at least two consecutive days starting from their first login date, then divide that number by the total number of players.\n\n# Approach\nIn this problem we can break it down into 3 parts\n1. Get first logged in day\n2. Return #of users that logged in two consecutive days\n3. Get the total count of users\n\n# Complexity\n- Time complexity:\n**2984 ms**\n\n# Code\nFull solution below here is the steps\n1. Get first logged in day\n```\nSELECT player_id ,MIN(event_date ) as event_date -- Return first logged in day\nFROM Activity\nGROUP BY  player_id\n```\n2. Return #of users that logged in the next day after first log\n```\nSELECT COUNT( DISTINCT a1.player_id)\nFROM (\n    SELECT player_id ,MIN(event_date ) as event_date -- Return first logged in day\n    FROM Activity\n    GROUP BY  player_id\n) a1\nINNER JOIN Activity a2 ON a1.player_id = a2.player_id \nWHERE DATEDIFF(day,a1.event_date,a2.event_date) =1-- and a2.event_date\n```\n3. Get the total count of users\n```\nSELECT COUNT(DISTINCT player_id )  -- get the total players count\nFROM Activity \n```\n\n# Full Solution\n```\nSELECT ROUND((COUNT( DISTINCT a1.player_id)*1.0)/(\n    SELECT COUNT(DISTINCT player_id )  -- get the total players count\n    FROM Activity \n),2) as fraction\nFROM (\n    SELECT player_id ,MIN(event_date ) as event_date -- Return first logged in day\n    FROM Activity\n    GROUP BY  player_id\n) a1\nINNER JOIN Activity a2 ON a1.player_id = a2.player_id \nWHERE DATEDIFF(day,a1.event_date,a2.event_date) =1-- and a2.event_date\n\n```\n### ***Please Upvote my solution, if you find it helpful :)***\n\n![image.png](https://assets.leetcode.com/users/images/55f37141-561c-4f11-97c8-8931b61093f5_1705524207.5253394.png)\n
['MS SQL Server']