…
…
Read the schema yourself in a five-table music app; use joins and grouping to write the per-artist term report in eight steps.
Earbud is a small music app. The product team wants a report for the fall 2026 term (September–November) and asks five questions: which artists are being played, which songs were never opened, what premium listeners play, who joined through an invitation, and whether the numbers in the report are really correct.
You are seeing this database for the first time. How the tables connect is not written below; in the first steps you will find out yourself by looking at the columns.
Data: five tables, fictional sample data.
artist: id, name, genre, city (8 artists)song: id, title, artist_id, duration_sec (seconds), release_year (30 songs)listener: id, nickname, city, plan ('free' or 'premium'), joined_on, invited_by_id (25 listeners)play: id, listener_id, song_id, played_on, seconds_played (time played)song_like: listener_id, song_id, liked_onLessons used: grouping and aggregation (11–13), relationships and joins (14–18). There is no new concept; in a different database you will use together what you learned in the unit.
The cells contain only comment lines and ___: you will write the query. The first line of every cell starts with "Why this query:"; complete it with one sentence before you write the query (it is not checked, it only helps you think).
Every step only reads; you can re-run the cells as many times as you like.
What you'll do
Required topics
earbud.sqlDownload file
Reading file…
Code cells are for members
You can read the steps. Sign up free to run the code, complete the steps and save your progress.
You are seeing Earbud's database for the first time. Before you start the report, you need to understand how the tables connect. The first question: what is the most songs one artist has? That number also tells you in which direction the relationship between artist and song is "many".
Count the songs per artist. The result should have two columns: artist_id and song_count. The artist with the most songs comes first.
Look at the output: how many rows came back, and are all eight artists there? The missing artist will come back in step 4.
This step's code cell is for members.Sign up free
The product team wants to show a "longest songs" list on the home page. The song title is in the song table and the artist name is in the artist table. You will need to join the two tables.
Watch out: both tables have an id column, but not every id matches the other. You saw which column links to which in step 1. If you match the wrong columns, the query does not fail; you just get the wrong artists. Compare your result with the expected output.
Code cells are for members
You can read the steps. Sign up free to run the code, complete the steps and save your progress.
Show the title (title), the artist's name (artist), and the duration (duration_sec) of the 5 longest songs; the longest song comes first.
This step's code cell is for members.Sign up free
The catalog has songs that nobody played this term. The team is thinking of promoting them. Whether a song was played shows in the rows of the play table; a song that was never played has no rows there at all.
An inner join returns only matching rows. Think about which join you need to see a song with no match.
Show the title and the artist's name of the songs that were never played.
This step's code cell is for members.Sign up free
The team asks how many songs each of the eight artists has in the app. The query in step 1 returned only artists who have songs. Here an artist with no songs must stay in the list and show a song count of 0.
Watch two things: which table's rows must be kept, and what are you counting? An artist with no match still has one row after the join.
Show the artist's name (name) and the song count (song_count). The result should have 8 rows.
This step's code cell is for members.Sign up free
The team wants to understand the value of premium and would like to see, one by one, what premium listeners played in November 2026. This question touches four tables: who played (listener), when (play), which song (song), and whose song it is (artist).
Draw the path first: which table do you start from and over which columns do you move on? Then filter, and sort last. You can filter the date with a range: p.played_on >= '2026-11-01'.
Show the listener's nickname, the song title, the artist's name, and the play date; sort by date from oldest to newest. Giving aliases (AS song, AS artist) makes the output readable and tells apart the two columns that could be called a name or title.
This step's code cell is for members.Sign up free
Some Earbud listeners joined through a friend's invitation. The inviter is stored in the invited_by_id column of the same table. For an invitation reward, the team wants the 3 listeners who brought in the most people.
In this question the listener table plays two roles: the invited listener (l) and the inviter (i). Direction matters: if you set the condition backwards, the query runs but you count the invited listeners, not the inviters.
Show the inviter's nickname (inviter) and the number of people they invited (invitees); the one who invited the most comes first, and only the top 3.
This step's code cell is for members.Sign up free
A teammate wrote the query below, which gives the plays and likes per song. It runs, but the product team objects: "Coffee Stain can't have 48 likes, we only have 25 listeners in total." Also, some songs are missing from the list.
Run the query and check the numbers. You can find a song's plays and likes separately with small queries and compare them. Then fix the report: each song's plays and likes should be correct, and songs that were never played should show up with 0. Keep the columns the same: id, title, plays, likes.
This step's code cell is for members.Sign up free
Now you will write the report the product team really wants, from scratch. Four numbers per artist:
songs)plays)listeners): the same listener may have played a song several timesminutes): the sum of the seconds_played column, converted to minutes and roundedAll artists should show up (even one with no songs); the most-played artist comes first. Name the columns name, songs, plays, listeners, minutes.
Think before you write: what should one row represent, which tables will you go through, and which count could inflate because of multiplying rows? Calculate the minutes with the pattern ROUND(SUM(...) / 60.0); 60.0 makes the division use decimals.
Once your report matches, try one extra question in the same cell (not checked): keep only artists with at least 20 plays. Finally, look at the first row of the report: what does that row tell the product team, and what does it not tell them? For example, does being played a lot mean being loved or reaching many people?
This step's code cell is for members.Sign up free