Solution Using Self Join (Beats 98.83%)
Intuition\nInspired by a previous problem utilizing self-joining with date_add in the joining condition. This solution may not be the most optimal (still beats 
# Intuition\nInspired by a previous problem utilizing self-joining with date_add in the joining condition. This solution may not be the most optimal (still beats 98%), but I believe it is easier for new learners to grasp. I will explain it as intuitively as I can.\n\n# Approach\n\nHere is my thought process, step by step:\n\n**1. We just need to obtain a single value, \'fraction\'**\n\nThe fraction we need to obtain is the number of players who logged in  for at least 2 consecutive days out of all players. We can get the numerator and demoninator for this.\n\n```\nCOUNT(distinct a1.player_id)/(SELECT count(distinct player_id) FROM Activity\n```\n\nFor the denomiator, we use the current given table Activity to count the number of \'distinct\' player_id\'s, which tells us the total number of unique players. The reason I obtain this using a subquery (seperate select clause) is because for my numerator, I also want to count the number of distinct player_id\'s, but pulled from a modified version of the current table.\n\nFor the numerator, I want to also select player_id\'s, but only those players who meet the conditions, which I will explain below\n\n**2. Query Conditions for Players who Login Consecutively**\n\nThe intuition behind these operations is: we want to pair each entry in the table with another entry that represents the player\'s login the next day. If this pair exists, it indicates that the player has logged in consecutively, and we add it to the numerator count. Therefore, we perform a self-join on the Activity table to combine a date with a date that occurs 1 day later, if it exists.\n\n```\nActivity a1 JOIN Activity a2\nON a1.event_date = DATE_ADD(a2.event_date,INTERVAL 1 DAY) AND a1.player_id = a2.player_id\n```\n\nHere, a2 represents a login date, and a1 represents the potential second day after a2. The JOIN statement will only show all entries where these conditions are satisfied, and we will get a resulting table with two date columns, a1\'s date occuring the day after the a2\'s date.\n\n```\nWHERE (a2.player_id,a2.event_date) IN\n  (SELECT player_id,min(event_date) FROM Activity GROUP BY player_id)\n```\n\nFor the last part of our query, we want to take the joined table we just acquired above and select cases where  a2.event_date is equal to the first event_date for a given player. \n\nThis ensures that for the comparison above, a1 is one day ahead of the first day logged in.\n\nNow, going back to our intial select clause:\n```\nCOUNT(distinct a1.player_id)\n```\nWe just count every unique player that has logged in the day after their first, which is selected from the conditions we created above. It does not matter if you select a2.player_id or a1.player_id, as in the join condition we set a1\'s player_id equal to a2\'s player_id.\n\nHere is the full solution below:\n# Code\n```\n# Write your MySQL query statement below\nSELECT ROUND(COUNT(distinct a1.player_id)/(SELECT count(distinct player_id) FROM Activity),2) as fraction FROM Activity a1 \nJOIN Activity a2\n    ON a1.event_date = DATE_ADD(a2.event_date,INTERVAL 1 DAY) AND a1.player_id = a2.player_id\nWHERE (a2.player_id,a2.event_date) IN\n  (SELECT player_id,min(event_date) FROM Activity \n   GROUP BY player_id)\n\n```\n\nI hope this explanation helped! I will attempt to monitor the comment section and explain my thought process further to those who need clarification. I\'m still leaning, so please correct me where I am wrong.
['MySQL']