topskill.dev
CoursesTracks
All courses/Data Analysis Using SQLRequire the funnel steps to happen in sequence
Cohorts, funnels, and member segments
9 / 19
← Data Analysis Using SQL
○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
○Quarter review 1: freeze the report population○Quarter review 2: apply the refund cutoff once○Quarter review 3: regional evidence with an unmatched bucket○Quarter review 4: a monthly trend with a stable definition○Quarter review 5: publish a reconciled evidence table✦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

Require the funnel steps to happen in sequence

Data model

Example data

These objects are loaded at the start. Only the query inputs and their required lineage are listed; other tables in a shared seed are not part of this report.

seed_steps

One row represents one recorded seed-library step occurrence.

Field / SQL typeMeaningRules
reader · textReader name label shared by this person's steps; not a foreign key.Nullable; NULL means the identifier or reference is unrecorded.
step · textStep label: browse, reserve or collect in the example; not a constrained list.Nullable; NULL means no step value is recorded.
at · timestamp with time zoneStep occurrence instant in UTC; simultaneous instants do not establish strict sequence.Nullable; NULL means occurrence time is unrecorded.

No primary or unique key is declared; distinct sample identifiers are not a uniqueness guarantee.

There is no event key or separate receipt time. The aliases select different roles from this one physical table; early collection cannot complete a later reservation path.

Named intermediate results

These dictionaries describe the columns exposed by the named query steps. They are not extra preloaded tables or a complete answer query.

entry

One row represents one reader entry path.

Field / SQL typeMeaningRules
reader · textLogical reader identity for this path.May be NULL under its source or expression policy. Unique grouped identity in the supplied path; missing source identities remain possible.
entered · timestamp with time zoneFirst browsing occurrence in UTC.May be NULL under its source or expression policy. The exercise entry predicate excludes missing occurrence times; the demo source itself permits them.

This CTE is statement-local; it has no independently declared primary key, foreign key or NOT NULL constraint.

Successive left joins retain failed paths. Timestamp predicates select ordered successors; they are not foreign-key relationships. Grouped path identity is logical, not a physical constraint.

reserved

One row represents one reader entry path.

Field / SQL typeMeaningRules
reader · textLogical reader identity for this path.May be NULL under its source or expression policy. Unique grouped identity in the supplied path; missing source identities remain possible.
entered · timestamp with time zoneFirst browsing occurrence in UTC.May be NULL under its source or expression policy. The exercise entry predicate excludes missing occurrence times; the demo source itself permits them.
reserved · timestamp with time zoneFirst reservation strictly after entry within its allowed follow-up.May be NULL under its source or expression policy. NULL means no qualifying reservation was found; a failed path is retained.

This CTE is statement-local; it has no independently declared primary key, foreign key or NOT NULL constraint.

Successive left joins retain failed paths. Timestamp predicates select ordered successors; they are not foreign-key relationships. Grouped path identity is logical, not a physical constraint.

Relationship map

Aliases name query roles, not extra tables: v = entry, e = seed_steps, r = reserved.

Each seed_steps row can match zero or one entry rows; each entry row can match zero or many seed_steps rows. The stated keys and grouped or deduplicated grain determine these match limits; a child matching column can repeat unless its constraints or query grain make that value unique. Column names alone do not guarantee uniqueness. This is a logical query match, not a declared foreign key between these inputs. Missing or unmatched references need not have a parent. Sequence/time predicates further restrict eligible successors; pre-entry or simultaneous events do not establish a strict successor. Grouping restores one path row after matching multiple event candidates.

Each seed_steps row can match zero or one reserved rows; each reserved row can match zero or many seed_steps rows. The stated keys and grouped or deduplicated grain determine these match limits; a child matching column can repeat unless its constraints or query grain make that value unique. Column names alone do not guarantee uniqueness. This is a logical query match, not a declared foreign key between these inputs. Missing or unmatched references need not have a parent. Sequence/time predicates further restrict eligible successors; pre-entry or simultaneous events do not establish a strict successor. Grouping restores one path row after matching multiple event candidates.

An inner join omits nonmatches. A left join retains its left population and a full join retains both populations, using NULLs only for the missing side. These outer-join NULLs differ from unknown values stored in a real row. A one-to-many detail match repeats the other side's fields; preaggregate before summing parent-level money. An EXISTS test only asks whether a match exists and does not copy all matching child rows.

Seeing visit, book, and pay somewhere in a history does not prove that a member completed that path. A funnel must enforce order and a time limit.

This funnel starts at each member's first visit in the entry window. Find the first booking strictly after that visit, then the first payment strictly after that booking. Each later step must occur no more than 14 days after entry. We allow unrelated events between steps, but simultaneous timestamps do not establish the strict order required here.

Use separate CTEs with MIN and conditional join predicates for the successive steps. A booking before the visit cannot be rescued by taking independent minimum timestamps. Retain failed paths with left joins. Count people at each stage, not event rows. Event retries should be deduplicated when they could affect counts; taking a MIN timestamp alone is insensitive to an exact duplicate timestamp, but that does not make raw event counts safe.

Read and run

A seed library tracks browsing, reserving, and collecting. Jo has an early collection that must not complete a later path.

sql
WITH entry AS (
  SELECT reader, MIN(at) AS entered
  FROM seed_steps WHERE step = 'browse' GROUP BY reader
), reserved AS (
  SELECT v.reader, v.entered, MIN(e.at) AS reserved
  FROM entry v
  LEFT JOIN seed_steps e ON e.reader = v.reader
   AND e.step = 'reserve' AND e.at > v.entered
   AND e.at <= v.entered + INTERVAL '14 days'
  GROUP BY v.reader, v.entered
)
SELECT r.reader, r.reserved IS NOT NULL AS reserved,
       MIN(e.at) IS NOT NULL AS collected
FROM reserved r
LEFT JOIN seed_steps e ON e.reader = r.reader
 AND e.step = 'collect' AND e.at > r.reserved
 AND e.at <= r.entered + INTERVAL '14 days'
GROUP BY r.reader, r.reserved ORDER BY r.reader;

Both readers reserve, but only Lu completes collection after reservation. Jo has all three event names, yet the only collection happened too early.

If Lu collected before reserving, that collection would not complete this path. Having every event name is insufficient.