Leetcode Problem 550. Game Play Analysis IV

550. Game Play Analysis IV

Leetcode Solutions

Approach: CTEs and INNER JOIN

Core Logic Steps for Code Implementation

  1. Create a CTE named first_logins to select the minimum event_date for each player_id from the Activity table, grouping by player_id.

  2. Create a CTE named consec_logins to count the number of players who logged in the day after their first login. This is done by joining the first_logins CTE with the Activity table on player_id and checking if the event_date from Activity is one day after the first_login date.

  3. In the final SELECT statement, calculate the fraction by dividing the count of consecutive logins by the total count of players from the first_logins CTE. Round the result to two decimal places.

  4. Return the result as a single column named fraction.


erDiagram
    Activity {
        int player_id
        int device_id
        date event_date
        int games_played
        player_id event_date PK
    }

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...