Game Play Analysis III

You can write a query using a subquery and the SUM window function to achieve this. Here’s the query:

1
2
3
4
SELECT player_id, event_date,
       SUM(games_played) OVER (PARTITION BY player_id ORDER BY event_date) AS games_played_so_far
FROM Activity
ORDER BY player_id, event_date;

Explanation:

  • The SUM window function is used to calculate the cumulative sum of the games_played column for each player (partitioned by player_id).
  • The ORDER BY event_date inside the window function ensures that the cumulative sum is calculated in the order of the login dates for each player.
  • The final result shows the total number of games played by each player until each login date.