Longest Support Sessions per Channel
Problem
A help desk handles sessions over two channels: `chat` and `voice`. The table `Agents` lists each agent's `agent_id` and `given_name`; the table `Sessions` lists each session's `agent_id`, the `channel` it ran on, and its `seconds_long` (the session length in seconds). For each channel, find the three longest sessions. Return the agent's `given_name`, the `channel`, and the duration as `clock` formatted HH:MM:SS. If two sessions tie on length they are both kept (ranking by length, ties sharing a rank). Order the result by `channel`, then by duration descending, then by `given_name` descending for ties.
Tables
Example rows — the live problem includes the full dataset.
| agent_id | given_name | surname |
|---|---|---|
| 1 | Liam | Carter |
| 2 | Nora | Patel |
| 3 | Owen | Reyes |
| agent_id | channel | seconds_long |
|---|---|---|
| 1 | chat | 120 |
| 1 | voice | 180 |
| 2 | chat | 300 |
Expected output
Your answer should return 6 rows with the columns given_name, channel, clock.
Starter code (SQL)
SELECT *
FROM Agents;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