Streamhub's platform monitoring team is investigating a potential connection leak and needs to see all sessions still in progress.
Write a query to return the ID and start time of every open session.
Assumptions:
- The
sessionstable contains every session ever recorded on the Streamhub platform. - The
ended_atcolumn records when each session closed; sessions still in progress haveended_atset toNULL.
Output:
- One row per open session, with columns
idandstarted_at.
Schema · analytics 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
id,
started_at
FROM
sessions
WHERE
ended_at IS NULL The shape
"Still in progress" is encoded as the absence of an end time. Streamhub's session table has no boolean is_open flag — it has an ended_at column that gets filled in only when the session closes. IS NULL on that column is the open-session filter.
Clause by clause
SELECT id, started_atreturns the two columns the monitoring team needs — which session, and when it started.ended_atstays out of the output; it'sNULLfor every row in the result.FROM sessionsreads the session log. The prompt's assumption that this table contains every session ever recorded is what makes this a complete scan, not a sample.WHERE ended_at IS NULLkeeps only rows where the end timestamp is absent.IS NULLreturnstruefor in-progress sessions andfalsefor closed ones.
The trap
WHERE ended_at = NULL returns zero rows on a connection-leak investigation, which is exactly when a false-empty result is most dangerous. The query reports "no open sessions" while the leak is still active. = against NULL evaluates to unknown, never true. IS NULL is the only operator that detects absence.
You practiced using a NULL filter to identify in-progress records. The 'still open / not yet finished' pattern recurs anywhere a status is captured by an end-timestamp column rather than a boolean flag.