Course Overview
Data Analysis Using SQL
You know basic SELECT, filters, and joins. This course starts with a short practical refresh, then asks you to build reports that survive awkward data: unknown amounts, duplicate arrivals, unmatched members, ties, and exact date boundaries.
Each topic begins with a runnable worked example and continues with an editable SQL exercise on a different reporting task. Run the example, predict its behavior, then write the exercise query yourself. Use Run to inspect your result and Submit to compare its columns and rows with the report contract. The reference solution is one implementation, not the only correct SQL. Result-based checks cannot prove that you used a particular technique or created every intended constraint, so follow the named modeling and query requirements as well as the output contract.
What you will build
- An intake-quality report in three cumulative stages after cleaning and metric definitions.
- A refund-adjusted ledger in three cumulative stages after join-grain and missing-match practice.
- A daily operations briefing in three cumulative stages after calendar and window-function practice.
- A five-stage quarter-review capstone with its own Beacon tool library snapshot, carried-forward reporting views, independent stage seeds, and a reconciled board evidence table.
- A six-stage game churn investigation after the quarter review, using a separate Lantern Trail player/event snapshot, explicit baseline eligibility, complete follow-up, and a reconciled investigation queue.
A project stage starts from the previous stage's completed script. Its seed also restores earlier views, so you can run every stage independently. Run and Submit reset a coding lesson to its supplied snapshot; your previous attempt does not change the next result. Interactive examples use their own small datasets and do not change the exercise snapshot.
Reading the data
Most exercises use the fictional Harbor repair club. The capstone uses Beacon tool library with the same units and column meanings but different records. Demo datasets are separate illustrations, not hidden copies of the exercise answers. Some starters preview source rows; others return a not finished checkpoint until you replace it. You can inspect the named source tables with SELECT while exploring; restore your report as the final SELECT before submitting.
An order is not an event record or an order line. Order amounts are totals, so do not multiply them by line units. The sample deliberately includes unmatched member 99, missing fees, a duplicate event, tied values and timestamps, zero-activity members, and midnight boundaries. These are teaching records, not a production ledger. In particular, events and order payments are separate sources and need not reconcile one for one.
Unless a task states another window, use the supplied full snapshot. Quarter reports use 2025-01-01 00:00 UTC inclusive to 2025-04-01 00:00 UTC exclusive. Behavioral analyses use a fixed as-of date of April 1, 2025; never use today's date. Paid gross revenue excludes pending/cancelled orders. Net revenue subtracts recorded refunds under the task's stated cutoff. Unknown is not automatically zero.
Reporting discipline
Name the question, population, row grain, units, and time cutoff before writing a metric. Preserve a path from a summary back to its input keys. Compare counts before and after joins. Keep missing values, zero values, and unobserved future periods distinct. End a finding with what the data supports and what it does not establish; an observed association is not a causal effect.
The SQL uses PostgreSQL syntax, including FILTER, date series, window frames, and ordered-set percentiles. This is an analysis course, not a database administration course. Server provisioning, permissions, backup operations, distributed warehouses, and production performance benchmarking are outside its scope. The plan and index lessons are an introduction to measurement on representative data, not a promise of a faster query on a tiny fixture.
Recommended background
Already familiar with these topics? You can start and finish this course without completing the recommendations. Knowledge gained elsewhere is enough; no waiver is needed.
- Introduction to SQL
Be comfortable with SELECT, filtering, joins, grouping, and reusable queries.
Syllabus
- Define the row before the metric
- Exercise: define the row before the metric
- Profile missing values without hiding them
- Exercise: profile missing values without hiding them
- Group records by a business key
- Exercise: Group records by a business key
- Filter completed groups with HAVING
- Exercise: Filter completed groups with HAVING
- ✦Module Quiz
- Remove surrounding spaces with TRIM
- Exercise: Remove surrounding spaces with TRIM
- Normalize case with LOWER
- Exercise: Normalize case with LOWER
- Mark a blank as missing with NULLIF
- Exercise: Mark a blank as missing with NULLIF
- Choose a display fallback with COALESCE
- Exercise: Choose a display fallback with COALESCE
- Test decimal text with a regular expression
- Exercise: Test decimal text with a regular expression
- Choose a result value with CASE
- Exercise: Choose a result value with CASE
- Convert approved text to numeric
- Exercise: Convert approved text to numeric
- ✦Module Quiz
- Sum a measure at the chosen grain
- Exercise: Sum a measure at the chosen grain
- Calculate the mean of known observations
- Exercise: Calculate the mean of known observations
- Find the smallest known observation
- Exercise: Find the smallest known observation
- Find the largest known observation
- Exercise: Find the largest known observation
- Round a numeric report value
- Exercise: Round a numeric report value
- ✦Module Quiz
- Count matching rows with FILTER
- Exercise: Count matching rows with FILTER
- Define both sides of a rate
- Exercise: Define both sides of a rate
- Compare a row with a computed benchmark
- Exercise: compare a row with a computed benchmark
- Name analysis steps with CTEs
- Exercise: name analysis steps with CTEs
- Publish a query definition as a view
- Exercise: Publish a query definition as a view
- Commit a reporting change as one transaction
- Exercise: Commit a reporting change as one transaction
- Intake project 1: a reviewable clean layer
- Intake project 2: region coverage
- Intake project 3: one defensible coverage rate
- ✦Module Quiz
- Make unmatched records visible
- Exercise: make unmatched records visible
- Prevent join fanout with preaggregation
- Exercise: prevent join fanout with preaggregation
- Use existence when you do not need child rows
- Exercise: use existence when you do not need child rows
- Refund project 1: one row per refunded order
- Refund project 2: preserve the paid-order population
- Refund project 3: reconcile the regional ledger
- ✦Module Quiz
- Interpret an instant in a reporting zone
- Exercise: Interpret an instant in a reporting zone
- Keep adjacent time periods separate
- Exercise: Keep adjacent time periods separate
- Bucket calendar months without losing the year
- Exercise: bucket calendar months without losing the year
- Advance a calendar boundary with INTERVAL
- Exercise: Advance a calendar boundary with INTERVAL
- Read a date component with EXTRACT
- Exercise: Read a date component with EXTRACT
- Fill calendar gaps before measuring trends
- Exercise: fill calendar gaps before measuring trends
- ✦Module Quiz
- Keep detail rows while computing group shares
- Exercise: keep detail rows while computing group shares
- Assign a unique position with ROW_NUMBER
- Exercise: Assign a unique position with ROW_NUMBER
- Share tied positions with RANK
- Exercise: Share tied positions with RANK
- Number distinct value levels with DENSE_RANK
- Exercise: Number distinct value levels with DENSE_RANK
- Retain one source version per event
- Exercise: Retain one source version per event
- ✦Module Quiz
- Look back one observation with LAG
- Exercise: Look back one observation with LAG
- Look ahead one observation with LEAD
- Exercise: Look ahead one observation with LEAD
- Accumulate a running total with an explicit frame
- Exercise: Accumulate a running total with an explicit frame
- Restrict a total to a trailing row window
- Exercise: Restrict a total to a trailing row window
- Interpolate a percentile with PERCENTILE_CONT
- Exercise: Interpolate a percentile with PERCENTILE_CONT
- Choose an observed percentile with PERCENTILE_DISC
- Exercise: Choose an observed percentile with PERCENTILE_DISC
- Daily briefing 1: a complete daily layer
- Daily briefing 2: cumulative and trailing totals
- Daily briefing 3: changes with honest baselines
- Rank a review queue without erasing ties
- Exercise: rank a review queue without erasing ties
- ✦Module Quiz
- Build a cohort from the first eligible purchase
- Exercise: build a cohort from the first eligible purchase
- Reduce repeated activity to one row per combination
- Exercise: Reduce repeated activity to one row per combination
- Count distinct known identities
- Exercise: Count distinct known identities
- Separate zero retention from an unobserved period
- Exercise: separate zero retention from an unobserved period
- Require the funnel steps to happen in sequence
- Exercise: require the funnel steps to happen in sequence
- Measure recency at a fixed cutoff
- Exercise: Measure recency at a fixed cutoff
- Measure purchase frequency at order grain
- Exercise: Measure purchase frequency at order grain
- State the monetary measure in a member report
- Exercise: State the monetary measure in a member report
- Apply a segment policy to prepared RFM measures
- Exercise: Apply a segment policy to prepared RFM measures
- ✦Module Quiz
- Create an empty reporting table
- Exercise: Create an empty reporting table
- Protect report row identity with a primary key
- Exercise: Protect report row identity with a primary key
- Protect a reporting relationship with REFERENCES
- Exercise: Protect a reporting relationship with REFERENCES
- Load query results with INSERT ... SELECT
- Exercise: Load query results with INSERT ... SELECT
- Model a report with facts and dimensions
- Exercise: model a report with facts and dimensions
- Reconcile independent sources and name the limits
- Exercise: reconcile independent sources and name the limits
- Inspect the proposed query plan
- Exercise: Inspect the proposed query plan
- Declare an index for a filter column
- Exercise: Declare an index for a filter column
- ✦Module Quiz
- Define activity churn before counting players
- Stage 1: establish the observed play stream
- Stage 2: preserve each player and last-seen history
- Stage 3: classify inactivity without losing exclusions
- Stage 4: compare cohort and channel denominators
- Stage 5: reconcile eligibility and boundary cases
- Stage 6: prioritize investigation with honest evidence
- ✦Module Quiz