N002-H2 Tier 1 · Foundations · hard analytics · Streamhub

Return every reporting period's numeric ID, display name, and the month numbers that define its start and end

Part of FROM and Table References in SQL

The problem

Streamhub's BI team is configuring a reporting framework that segments metrics by named calendar windows (Q1, holiday season, etc.).

Write a query to return every reporting period's numeric ID, display name, and the month numbers that define its start and end.

Assumptions:

  • The periods table contains the calendar windows Streamhub uses to bucket metrics.
  • Each row has an id, a name, a start_month, and an end_month (both expressed as month numbers, 1–12).

Output:

  • One row per period, with columns id, name, start_month, and end_month.
Schema · analytics 5 tables
users
id integer
name text
email text
country text
plan text
signed_up_at timestamptz
is_active boolean
conversions
id integer
user_id integer
converted_at timestamptz
plan text
amount numeric
sessions
id integer
user_id integer
started_at timestamptz
ended_at? timestamptz
event_count integer
events
id integer
user_id integer
session_id? integer
event_type text
occurred_at timestamptz
properties? jsonb
periods
id integer
name text
start_month integer
end_month integer

Run previews · Check grades

Write a query, then run it to see results here.

Worked solution Try it yourself first
Solution query
SELECT
  id,
  name,
  start_month,
  end_month
FROM
  periods

The shape

FROM periods reads the lookup table that defines Streamhub's reporting windows, and the four columns in the SELECT list hand back the full definition of each window: its identifier, its display label, and the month boundaries that mark where it begins and ends.

Clause by clause

  • SELECT id, name, start_month, end_month returns four columns per row, in source order. The identifier comes first so the reporting framework can reference each period unambiguously, then the human-readable name (Q1, holiday season, and so on), then the two integer month numbers that define the window. The month numbers land as integers, between 1 and 12, exactly as the prompt describes.
  • FROM periods is the row source — the configuration table that defines how the reporting framework slices the calendar. There's no WHERE clause because the framework needs the full set of period definitions; filtering would mean some windows wouldn't render, and the bucketing logic downstream would have gaps.

Why this and not hardcoding the windows

The periods could in principle be hardcoded in every report that needs to bucket metrics — write WHERE month BETWEEN 1 AND 3 for Q1, repeat that pattern wherever quarter logic appears. That works on day one and breaks the moment the business decides Q1 actually ends in February for fiscal reasons, or that the holiday season this year starts on a different date than last year. Every report would have to be tracked down and updated by hand.

A periods table is the alternative. The window definitions live in one place; reports read from the table; updating the business calendar means updating one row, and every report that joins against periods reflects the change automatically. Reading the table directly is how the framework exposes those definitions to whatever code generates the reports.

The trap

Treating a small, slow-changing lookup table as too simple to bother with. The periods table only has a handful of rows, and a learner might assume the query should be more complicated than SELECT … FROM periods because the problem is marked Hard. It isn't. The hardness is recognising what role the table plays — the source of truth for how the rest of the analytics stack groups time — not the syntax of the query that reads it. Simple shape, load-bearing data.

You practiced reading a configuration-style table — small, stable rows that drive how other queries group time. Many analytics systems have a periods table or equivalent for this exact purpose.

How you actually get good at SQL

Reading explains SQL. Writing it, over and over with instant feedback, is what makes you fluent.

That's the whole SQLMaxx loop: 600+ real problems, instant AI feedback, mastery you can actually see, and spaced review that won't let you forget.

A stack of SQL practice problem cards, the top card showing an employees table.
615 problems · 66 concepts

Real problems. Not toy examples.

615 hand-built problems spanning all 66 concepts, from basic SELECTs to window functions, built on real schemas and real business questions, the kind you'll actually get asked on the job. Enough reps to make SQL automatic.

A retro computer showing a SQL query marked correct with a green checkmark.
Instant AI feedback

Write a query. Know if it's right in one second.

No copying an answer and hoping it clicked. The AI grader checks your real query against real data, catches exactly what's wrong, and explains the fix in plain English, like a senior analyst reading over your shoulder on every problem.

A circular mastery progress dial filling from blue to green, the SQLMaxx diamond at its center.
Mastery tracking

Stop guessing whether you actually know it.

SQLMaxx tracks every concept and shows you what you've mastered and what's still shaky. Your skills fill in one concept at a time, so 'I think I get joins' becomes something you can prove.

A SQL query editor circled by a blue return arrow with a clock, scheduled to come back for review.
Spaced review

Learn it once. Keep it for good.

Most of what you learn this week fades by next week. So when a concept comes due for review, SQLMaxx hands you a fresh problem to solve from a blank editor, not a flashcard to re-read. A research-backed spaced-repetition algorithm (FSRS) times each return for right before you'd forget, so your SQL is still there months later, when the interview or the job actually needs it.

Practice, feedback, mastery, review. That's the loop that turns reading into real skill.

Start free

No account, no credit card. Start solving in under a minute.