lets see if this works or not :)
Intuition\nI doing this using joins, and delibritly not using LEAD/LAG funcation just for the hack of it :) \n\n# Approach\n\n1. Define Aliases: The query start
# Intuition\nI doing this using joins, and delibritly not using LEAD/LAG funcation just for the hack of it :) \n\n# Approach\n\n1. **Define Aliases:** The query starts by defining aliases for the Activity table: A1 is used as an alias for the main Activity table, and A2 is an alias for a subquery.\n2. **Subquery to Find Second Login Date:**\n\u2022\tInside the LEFT JOIN, a subquery A2 is used to find the second login date for each player. (INNER JOIN will work better -): but I love unnessary data so left join)\n\u2022\tThis subquery groups the data by player_id and calculates the minimum event date for each player.\n\u2022\tIt then adds one day to the minimum event date using DATEADD(DAY, 1, MIN(event_date)) to get the second login date.\n**3.\tLeft Join:**\n\u2022\tThe main Activity table (A1) is left joined with the subquery A2 based on the player_id.\n\u2022\tThis join aims to pair each player\'s first login date (A1.event_date) with their second login date (A2.second_login).\n**4.\tCount and Fraction Calculation:**\n\u2022\tThe query then counts the number of records where A1.player_id is not null after the left join. This indicates that there was a second login.\n\u2022\tIt also counts the distinct player_id from the main Activity table A1.\n\u2022\tThe count of second logins (COUNT(A2.player_id)) is divided by the count of distinct player IDs (COUNT(DISTINCT A1.player_id)).\n\u2022\tThe result is rounded to two decimal places using the ROUND function.\n\n\n# Code\n```\n/* Write your T-SQL query statement below */\nSELECT ROUND(CAST(COUNT(A2.player_id) as decimal)/ CAST(COUNT(DISTINCT A1.player_id) as decimal), 2) AS fraction  \nFROM Activity AS A1\nLEFT JOIN \n(\n\tSELECT \n\t\tplayer_id,\n\t\tDATEADD(DAY, 1, MIN(event_date)) AS second_login\n\tFROM Activity\n\tGROUP BY player_id\n) AS A2\nON A1.player_id = A2.player_id\nAND A1.event_date = A2.second_login\n```
['MS SQL Server']