Query Systems · Knowledge Base
From first queries to advanced analytics. Joins, aggregation, and window functions; query reasoning and debugging; and the performance judgment to write SQL that stays correct — and cheap — at scale.
StartRead a table and its grain, shape a query, select and filter deliberately, handle types and NULLs, count safely, and inspect results like an engineer.
Read chapter →Join types, grain, cardinality, duplicate explosions, and the habit of proving why rows multiplied.
Read chapter →Grouped metrics, HAVING filters, distinct counts, conditional aggregation, and trustworthy metric definitions.
Read chapter →Layered query design, debuggable intermediate results, and SQL that is easy to narrate in interviews.
Read chapter →Ranking, offsets, running totals, deduplication, retention, cohorts, and event sequence analysis.
Read chapter →Timestamp logic, time zones, event tables, JSON, arrays, late data, and ordering tradeoffs.
Read chapter →UNION, INTERSECT and EXCEPT; pivoting with conditional aggregation, unpivoting with UNION ALL, and subtotal rows you cannot misread.
Read chapter →Deriving episodes from events: unbroken runs, streaks, sessionisation with a threshold, ordered funnels, and honest cohort retention.
Read chapter →Incremental loads, MERGE patterns, upserts, slowly changing dimensions, snapshots, and backfills.
Read chapter →Duplicate checks, null checks, referential tests, reconciliation, anomaly queries, and audit evidence.
Read chapter →What you are renting when you run SQL against a cloud warehouse, and which of the three layers — storage, compute, or metadata — to blame for a bill, a slow dashboard, or a load that did nothing.
Read chapter →Partitions, clustering, pruning, query plans, scan cost, and warehouse-aware optimization habits.
Read chapter →Clarifying assumptions, narrating query logic, debugging live, and explaining senior-level tradeoffs.
Read chapter →The transactional side of performance: B-trees, selectivity, sargable predicates, composite key order, index write cost, and why none of it exists on a warehouse.
Read chapter →Read the chapters, then test yourself: SQL interview questions, each with the short answer, the wrong answer and the follow-up.