SShortSingh.
Back to feed

SQL Guide Walks Through Cohort Retention Analysis Step by Step

0
·1 views

Data analyst Michael Nocito published a detailed tutorial on August 8, 2026, explaining how to build a cohort retention analysis using SQL. The guide uses a small dataset of 12 customers and 19 purchases, loaded into DuckDB, so readers can verify every result manually before scaling up. It walks through tagging each customer with their first purchase month, calculating how many months later subsequent purchases occurred, and counting distinct customers per cohort-month pair. The tutorial emphasizes defining the cohort metric precisely before writing any SQL, noting that first purchase, signup date, and first login each produce different results. The output takes the form of a triangular grid showing how many customers from each arrival month returned in subsequent months.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Developer's 0% test score was a false alarm caused by an empty API credit account

A developer using Claude Code discovered that a test report showing 0 out of 96 passing was not due to actual test failures, but because the account had run out of API credits. The incident exposed a fundamental flaw in how many evaluation scripts handle infrastructure failures — they report a zero score instead of signalling that measurement was impossible. Further investigation revealed a second bug: the scoring tool only captured stdout while warnings went to stderr, meaning it had never actually evaluated pass or fail results on any run. The developer also found that a handoff document incorrectly stated no test cases existed for 24 AI skills, when in fact all 24 had full test coverage. The episode highlights the importance of distinguishing between a failed test and a failure to run the test at all.

0
ProgrammingDEV Community ·

A Practical Guide to Database Indexing for Analysts: When and Why It Matters

Data analyst Michael Nocito published a practical guide on August 8, 2026, explaining when and how to use database indexes to speed up slow queries. The guide focuses on the fundamental difference between a full table scan, where the engine reads every row, and an index scan, where it jumps directly to the needed value using a sorted structure. Nocito demonstrates concepts using a 500,000-row SQLite orders table, with each query timed across five runs to provide real-world performance comparisons. Readers are shown how to use EXPLAIN QUERY PLAN to diagnose whether a query is scanning an entire table, a technique that works across major databases including PostgreSQL. The guide also covers the costs and limitations of indexes, including why an index on one column offers no benefit to queries filtering on a different column.

0
ProgrammingDEV Community ·

How a 100% Funnel Conversion Rate Usually Signals a Skippable Step

Data analyst Michael Nocito published a technical guide on August 8, 2026, explaining how to build funnel conversion queries in SQL using DuckDB. The tutorial walks through converting a raw events table into a step-by-step funnel, calculating the share of users progressing between stages. A central insight is that any funnel step converting at or near 100% is rarely a sign of perfect performance — it typically indicates a step that can be bypassed or is logged as a side effect of a later action. Nocito demonstrates this using a deliberately small dataset of 24 events across 10 sessions, making every number manually verifiable. The guide emphasizes defining three key parameters before writing any query: what is being counted, the ordered steps, and the time window over which conversions are measured.

0
ProgrammingDEV Community ·

How SQL Date Functions Prevent Missing Months When Grouping by Month

Data analyst Michael Nocito published a practical SQL guide on August 8, 2026, explaining how to correctly group database records by month without silently losing months that had no activity. The core technique uses DATE_TRUNC('month', date_column), which snaps every date to the first of its month, allowing GROUP BY to aggregate all dates within a month into a single value. Nocito warns that a missing month never becomes a row in results, meaning gaps can quietly skew comparisons in monthly reports. The guide covers date arithmetic, period filtering, and the differences between DATE, TIMESTAMP, and TIMESTAMP WITH TIME ZONE data types. All queries were tested in DuckDB and SQLite, with syntax largely compatible with PostgreSQL, Redshift, and Snowflake.