Practice Free
← Syllabus|
Hard

15. Net Revenue Retention (NRR) Cohort Performance

HardBusiness AnalyticsPostgreSQL 16PRO
Table: cohort_annual_revenue
+-----------------+------------+
| Column Name     | Type       |
+-----------------+------------+
| customer_id     | int        |
| cohort_year     | int        |
| starting_mrr    | numeric(10 |
| expansion_mrr   | numeric(10 |
| contraction_mrr | numeric(10 |
| churned_mrr     | numeric(10 |
+-----------------+------------+

customer_id is the unique key for this table. Each row contains record details for this enterprise dataset.

SaaS venture capital and finance teams evaluate company health through Net Revenue Retention (NRR), calculating whether expansion from existing accounts outpaces contraction and churn.

Write a query using a CTE to aggregate revenue metrics from `cohort_annual_revenue` for the `'2023'` cohort: - `starting_mrr`: sum of `starting_mrr` - `expansion_mrr`: sum of `expansion_mrr` - `contraction_mrr`: sum of `contraction_mrr` - `churned_mrr`: sum of `churned_mrr` Calculate `nrr_percentage` in the outer query as: `ROUND(((starting_mrr + expansion_mrr - contraction_mrr - churned_mrr) * 100.0) / starting_mrr, 2)`. Return: 1. `cohort_year` 2. `starting_mrr` 3. `ending_mrr`: `(starting_mrr + expansion_mrr - contraction_mrr - churned_mrr)` 4. `nrr_percentage` Order by `cohort_year` ASC.

Return the result table ordered as specified. The result format is in the following example.

Example 1:
Input:
Preparing sample rows...
Output:
Calculating benchmark target...
Explanation:

Cohort ending MRR and Net Revenue Retention rate percentage.

Constraints:
  • Query must utilize clause(s): WITHSUMROUND
  • Result order matters (tie-breakers and sort order must be strictly preserved).
  • Engine: PostgreSQL 16 standard syntax (in-browser WASM).
query.sql|PostgreSQL 16 WASM
Loading SQL editor...
You must run your code first

Write your SQL query in the editor and click Run or Submit to test against in-browser PostgreSQL 16 WASM.

About the “Net Revenue Retention (NRR) Cohort Performance” SQL Problem

Business Scenario

SaaS venture capital and finance teams evaluate company health through Net Revenue Retention (NRR), calculating whether expansion from existing accounts outpaces contraction and churn.

Expected Output & Criteria

Cohort ending MRR and Net Revenue Retention rate percentage.

Database Table Schema (PostgreSQL DDL)

PostgreSQL 16 WASM
CREATE TABLE cohort_annual_revenue (
        customer_id INT PRIMARY KEY,
        cohort_year INT NOT NULL,
        starting_mrr NUMERIC(10, 2) NOT NULL,
        expansion_mrr NUMERIC(10, 2) NOT NULL,
        contraction_mrr NUMERIC(10, 2) NOT NULL,
        churned_mrr NUMERIC(10, 2) NOT NULL
      );

Target SQL Clauses & Operators

WITHSUMROUND

Want more Business Analytics practice?

Explore the full syllabus of 18 exercises and syntax guides.

View Business Analytics Track