SQL Interview Questions – Leetcode 534 – Game Play Analysis III

Spread the love

Problem Description –

Write an SQL query that reports for each player and date, how many games played so far by the player. That is, the total number of games played by the player until that date. Check the example for clarity.

The query result format is in the following example:

Difficulty Level – Medium

Solution –

    SUM(games_played) OVER(PARTITION BY player_id ORDER BY event_date) as games_played_so_far
FROM Activity

The is a common running total problem in SQL, which can be solved by using the SUM() Window function.

Rating: 1 out of 5.

Leave a Reply