topskill.dev
CoursesTracks
All courses/Data Analysis Using SQLDefine activity churn before counting players
Game churn: a fixed-window player investigation
1 / 8
← 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

Define activity churn before counting players

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.

pebble_snapshot

One row represents one prepared Pebble Paths player snapshot.

Field / SQL typeMeaningRules
player_id · integerPlayer identifier; unique in the sample without a key declaration.Nullable; NULL means the identifier or reference is unrecorded.
mature · integerPrepared integer flag: 1 means the account has a full follow-up opportunity; 0 means not yet comparable.Nullable; NULL means no mature value is recorded.
baseline_plays · integerCompleted plays during June 1–7 UTC in the fixed example.Nullable; NULL means the baseline plays measure is unrecorded, not zero.
followup_plays · integerCompleted plays during June 8–14 UTC before the fixed June 15 cutoff.Nullable; NULL means the followup plays measure is unrecorded, not zero.

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

These are prepared counts, not event rows. The year is not encoded in this table. No CHECK enforces binary flags or nonnegative counts. Eligibility needs both maturity and positive baseline activity.

A quiet player is not automatically a lost customer. Before building Lantern Trail's report, separate an observed absence from a permanent decision to leave. This example uses a different game, Pebble Paths, and a shorter window so the denominator is easy to inspect.

The supplied player-level table already contains clean counts. At a fixed June 15 cutoff, its baseline covers June 1–7 and follow-up covers June 8–14, in UTC. Players 21 and 22 played in the baseline and have full follow-up; player 23 joined during follow-up. Player 24 has a mature account but never played in the baseline. Filter the eligible population before computing the rate.

sql
SELECT COUNT(*) AS eligible_players,
       COUNT(*) FILTER (WHERE followup_plays = 0)
         AS inactive_players,
       COUNT(*) FILTER (WHERE followup_plays > 0)
         AS retained_players,
       ROUND(
         100.0 * COUNT(*) FILTER (WHERE followup_plays = 0)
         / NULLIF(COUNT(*), 0), 2
       ) AS inactivity_pct
FROM pebble_snapshot
WHERE mature = 1 AND baseline_plays > 0;

The result contains two eligible players and splits them evenly. Counting all four registrations would dilute the rate; calling player 23 churned would also mistake an incomplete observation window for a completed outcome. Exact day-seven retention asks a different question and need not equal one minus this inactivity rate.

Predict whether adding another follow-up play for player 21 would change this player-based rate. It changes activity volume but not the binary outcome. The next lesson starts a six-stage report from raw event versions, rather than this already summarized table.

The game snapshot

You are reviewing the fictional cooperative puzzle game Lantern Trail. game_players has one row per account. Its integer player_id is a declared primary key, signed_up_at is a non-null timestamp with time zone, and channel is nullable text. game_events has one row per received event version. Its integer primary key ingest_id identifies the receipt; non-null text event_id identifies the logical event and may repeat. player_id is an integer logical link without a declared foreign key, so an orphan event can appear. kind is non-null text, and happened_at (occurrence) and received_at (arrival) are non-null timestamps with time zone. The report interprets these instants in UTC. A play is a completed puzzle attempt; a heartbeat is not play. These synthetic records describe no real players.

Use the fixed cutoff April 1, 2025 at 00:00 UTC, exclusively. Keep only events that both happened and arrived before that instant, retain the latest known version per event ID (arrival descending, then ingest ID descending), then keep plays matched to an account and occurring on or after signup. Assume this toy export covers all accounts from signup onward; in a real export verify tracking coverage and identity quality before interpreting silence.

The baseline is March 4 inclusive to March 18 exclusive. Follow-up is March 18 inclusive to April 1 exclusive. The eligible denominator contains accounts signed up by March 18 at 00:00 UTC with at least one valid baseline play. A member of that baseline cohort with no follow-up play is activity-churned for this report; any follow-up play means retained. This is an observed transition into a 14-day inactive window, not subscription cancellation, permanent departure, or a prediction. New accounts, never-players, and accounts absent from the baseline are reported separately, not added to that denominator.

The full follow-up window is observed for the eligible baseline cohort. Recent signups are right-censored for a comparable account-age follow-up: the export ends before they receive the same opportunity. Excluding them avoids labeling incomplete observation as churn. Signup-month cohorts below are descriptive strata of the fixed baseline population, not day-N retention curves. Retention and inactivity sum to 100% only because this report uses the same eligible cohort and complementary follow-up conditions.