How Often Each Host Was a Guest
Problem
A podcast platform records every recorded episode. Table `episodes` has `(episode_id, host_id, guest_id)` where `episode_id` is unique; `host_id` is the person running the episode and `guest_id` is the person invited onto it.
For each distinct person who has hosted at least one episode, report their id as `host_id` and `appearances`: the number of episodes in which that person appeared as a guest (0 if they were never a guest).
Return the result in any order.
Tables
Example rows — the live problem includes the full dataset.
| episode_id | host_id | guest_id |
|---|---|---|
| 1 | 10 | 20 |
| 2 | 10 | 30 |
| 3 | 20 | 10 |
Expected output
Your answer should return 3 rows with the columns host_id, appearances.
Starter code (SQL)
SELECT *
FROM episodes;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