AnalystPath

Most Versatile Studios

SQLMediumMid level~15 min

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
studio_idsignup_datehome_genre
12022-01-10jazz
22022-02-15rock
32022-03-20pop
release
release_idrelease_datetrack_idstudio_id
12023-01-011021
22023-01-051031
32023-01-081011
track
track_idgenre
101jazz
102rock
103pop

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

Related SQL questions