Most Versatile Studios
Problem
Table: `studio`
| Column Name | Type |
|---|---|
| studio_id | int |
| signup_date | date |
| home_genre | varchar(10) |
`studio_id` is the primary key. `home_genre` is the genre the studio is best known for.
Table: `release`
| Column Name | Type |
|---|---|
| release_id | int |
| release_date | date |
| track_id | int |
| studio_id | int |
`release_id` is the primary key. Each row is one track that a studio released.
Table: `track`
| Column Name | Type |
|---|---|
| track_id | int |
| genre | varchar(10) |
`track_id` is the primary key.
A studio shows range when it releases tracks in a genre other than its own `home_genre`. For each studio, count how many *distinct* tracks it released whose `genre` differs from the studio's `home_genre`. Return the studio (or studios, on a tie) with the highest such count, as `studio_id` and `outside_tracks`, ordered by `studio_id`.
Tables
Example rows — the live problem includes the full dataset.
| studio_id | signup_date | home_genre |
|---|---|---|
| 1 | 2022-01-10 | jazz |
| 2 | 2022-02-15 | rock |
| 3 | 2022-03-20 | pop |
| release_id | release_date | track_id | studio_id |
|---|---|---|---|
| 1 | 2023-01-01 | 102 | 1 |
| 2 | 2023-01-05 | 103 | 1 |
| 3 | 2023-01-08 | 101 | 1 |
| track_id | genre |
|---|---|
| 101 | jazz |
| 102 | rock |
| 103 | pop |
Expected output
Your answer should return 1 row with the columns studio_id, outside_tracks.
Starter code (SQL)
SELECT *
FROM studio;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock