AnalystPath

How Often Each Host Was a Guest

SQLMediumMid level~15 min

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.

episodes
episode_idhost_idguest_id
11020
21030
32010

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

Related SQL questions