Easy and Simple Solution | Beginner-friendly🚀
CodeIf you found this solution helpful, please give it an upvote! 🌟✨ It really motivates me to share more solutions like this. 😊👍
Happy coding! 💻🐱‍🏍
IntuitionWe
# Code
```mysql []
# Write your MySQL query statement below
select round(count(distinct player_id)/(select count(distinct player_id) from Activity),2) as fraction
from Activity
where (player_id,DATE_SUB(event_date,INTERVAL 1 DAY))
in (select player_id, min(event_date) as first_login from Activity group by player_id )
```
**If you found this solution helpful, please give it an upvote! 🌟✨ It really motivates me to share more solutions like this. 😊👍
Happy coding! 💻🐱‍🏍**
<img src="https://assets.leetcode.com/users/images/6e8c623a-1111-4d21-9a5b-54e00e7feabb_1738093236.165277.jpeg" width=250px>
# Intuition
We need to calculate the fraction of players whose **second login** happened exactly one day after their **first login**. The fraction should be rounded to two decimal places. 

The `Activity` table contains `player_id` and `event_date`, where:
- The **first login** for each player is determined using `MIN(event_date)`.
- We check if the player's **second login** happened exactly **one day after** their first login.
- Finally, we compute the fraction of such players among all players.

# Approach
1. **Find the first login date for each player**  
   - Use `MIN(event_date) AS first_login` for each `player_id` (grouped by `player_id`).

2. **Find players who logged in exactly one day after their first login**  
   - Use `WHERE (player_id, DATE_SUB(event_date, INTERVAL 1 DAY)) IN (...)`  
   - This checks if `(player_id, event_date - 1)` matches any `(player_id, first_login)`.

3. **Count the number of such players**  
   - Use `COUNT(DISTINCT player_id)` to ensure each player is counted only once.

4. **Compute the fraction of such players among all players**  
   - Divide by `COUNT(DISTINCT player_id) FROM Activity` (total unique players).
   - Use `ROUND(..., 2)` to round the result to two decimal places.

# Complexity Analysis
- **Finding first login (`MIN(event_date) GROUP BY player_id`)**  
  - This runs in **O(N log P)**, where `P` is the number of unique players.

- **Filtering for second login (`WHERE (player_id, DATE_SUB(event_date, INTERVAL 1 DAY)) IN (...)`)**  
  - The `IN` clause requires matching against first logins, leading to **O(N log P)** complexity.

- **Final aggregation (`COUNT(DISTINCT player_id)`)**  
  - Runs in **O(N)**.

### **Overall Complexity:**
- The dominant factors are **finding first logins and filtering for second logins**, leading to an approximate **O(N log P) ≈ O(N log N)** complexity in the worst case.
['MySQL']