0
← Exercises/
Window Functions•10 of 14
Window FunctionsAdvancedPRO

Cohort Cumulative Expansion Revenue Trajectory

Scenario

SaaS venture investors track net dollar retention. For each customer signup cohort, finance wants to observe cumulative expansion revenue accumulated over consecutive operating months.

Task
For each row in `cohort_expansions`, compute the running cumulative expansion revenue for that cohort. Return: 1. `cohort_name` 2. `activity_month` 3. `expansion_mrr` 4. `cumulative_expansion_mrr`: `SUM(expansion_mrr) OVER (PARTITION BY cohort_name ORDER BY activity_month ASC)` Order results by `cohort_name` ascending, then by `activity_month` ascending.
Expected Output Format

Monthly expansion MRR alongside cumulative cohort expansion total.

Input Tables & Sample Data0 tables
Loading database schema...
Need a hint?
query.sql|Local Sandbox
Loading SQL editor...
Click "Run" or press ⌘ + Enter to execute your query

About the “Cohort Cumulative Expansion Revenue Trajectory” SQL Problem

Business Scenario

SaaS venture investors track net dollar retention. For each customer signup cohort, finance wants to observe cumulative expansion revenue accumulated over consecutive operating months.

Expected Output & Criteria

Monthly expansion MRR alongside cumulative cohort expansion total.

Database Table Schema (PostgreSQL DDL)

PostgreSQL 16 WASM

This challenge executes directly against the following relational schema in your browser:

CREATE TABLE cohort_expansions (
        cohort_name VARCHAR(20) NOT NULL,
        activity_month DATE NOT NULL,
        expansion_mrr NUMERIC(10, 2) NOT NULL,
        PRIMARY KEY (cohort_name, activity_month)
      );

Target SQL Clauses & Operators

SUMOVERPARTITION BY

Want more Window Functions practice?

Explore the full syllabus of 14 exercises, syntax guides, and interview pitfalls.

View Window Functions Track→