3-line MySQL solution with explanation (Best for beginners)
Intuition\n Describe your first thoughts on how to solve this problem. \n- To find fraction, we use COUNT(*) with given conditions in the numerator.\n- For deno
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- To find fraction, we use **COUNT(*) with given conditions** in the numerator.\n- For denominator, we **count all the distinct players**, i.e. all players who ever logged-in.\n- There is a sub-query which defines the condition such that the **first_login date and any event_date have an interval of 1**.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. In the SELECT statement, we retrieve the **fraction** as calculated in the intuition section.\n2. In the FROM statement, we write the table name **Activity**.\n3. The **WHERE clause** defines the condition for finding an **event_date such that it has an interval of 1 day from first_login** where **first_login can be defined as MIN(event_date**).\n# Code\n```\n# Write your MySQL query statement below\nSELECT ROUND(COUNT(*) / (SELECT COUNT(DISTINCT player_id) FROM Activity),2) as fraction \nFROM Activity\nWHERE (player_id, DATE_SUB(event_date, INTERVAL 1 DAY)) IN \n(\n    SELECT player_id, MIN(event_date) as first_login FROM Activity GROUP BY player_id\n)\n```\n# Note\nPlease upvote if you find my solution helpful. If you have any doubts, suggestion or want to discuss any solution, comment it. If you wish to discuss other related topics, feel free to message me on LinkedIn, https://leetcode.com/prathams29/
['MySQL']