Knowledge Guide
HomeDatabasesSQL Practice Problems

Game Play Analysis I

Problem

Table: Activity

+--------------+---------+
| Column Name  | Type    |
+--------------+---------+
| player_id    | int     |
| device_id    | int     |
| event_date   | date    |
| games_played | int     |
+--------------+---------+
(player_id, event_date) is the primary key (combination of columns with unique values) of this table.
This table shows the activity of players of some games.
Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on someday using some device.

Problem Definition

Write a solution to find the first login date for each player.

Example

Image
Image

Output

Image
Image

Try It Yourself

java
-- TODO: Write your user queries here

Solution

The approach is to select the player_id and find the minimum event_date (representing the first login) for each player from the Activity table. The results can then grouped by player_id, providing insights into the earliest login date for each player.

SELECT player_id, Min(event_date) AS first_login FROM Activity GROUP BY player_id

Let's break down the query step by step:

Step 1: Select fields:

SELECT player_id, Min(event_date) AS first_login FROM Activity

The SELECT clause specifies the columns that will be included in the result set. In this case, it selects the player_id and calculates the minimum (earliest) event_date for each player.

Output After Step 1:

+-----------+-------------+ | player_id | first_login | +-----------+-------------+ | 1 | 2016-03-01 | | 1 | 2016-03-01 | | 2 | 2017-06-25 | | 3 | 2016-03-02 | | 3 | 2016-03-02 | +-----------+-------------+

Step 2: GROUP BY player_id:

GROUP BY player_id

The GROUP BY clause is used to group the results by a specific column or columns. In this query, it groups the activity data by the player_id.

The min(event_date) function is then applied to each group separately, calculating the earliest login date for each distinct player_id.

Final Output:

+-----------+-------------+ | player_id | first_login | +-----------+-------------+ | 1 | 2016-03-01 | | 2 | 2017-06-25 | | 3 | 2016-03-02 | +-----------+-------------+
🤖 Don't fully get this? Learn it with Claude

Stuck on Game Play Analysis I? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Game Play Analysis I** (Databases) and want to truly understand it. Explain Game Play Analysis I from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Game Play Analysis I** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Game Play Analysis I** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Game Play Analysis I** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes