Learn how to calculate critical business KPIs using grouped aggregations. Compute Monthly Recurring Revenue (MRR), delivery route SLA adherence, and refund rates with instant in-browser feedback.
Key patterns and rules practiced in this track.
Collapses multiple rows with identical dimension values into a single summary row, computing aggregates across each group.
SELECT dimension, COUNT(*), SUM(metric) FROM table GROUP BY dimensionSELECT plan_tier, COUNT(*) AS active_tenants, SUM(monthly_amount) AS total_mrr FROM subscriptions GROUP BY plan_tier;
WHERE filters individual rows before grouping occurs. HAVING filters aggregated group metrics after the GROUP BY is performed.
HAVING aggregate_function(column) >= thresholdSELECT merchant_id, SUM(amount) AS volume FROM transactions GROUP BY merchant_id HAVING COUNT(*) >= 50;
PostgreSQL standard syntax for conditional aggregation inside a single query without complex CASE statements.
COUNT(*) FILTER (WHERE condition)SELECT department, COUNT(*) AS total_staff, COUNT(*) FILTER (WHERE perf_rating >= 4.5) AS high_performers FROM employees GROUP BY department;
Click any problem to open the interactive editor.
Aggregate table showing tier, total_mrr, active_customers, and avg_seats for tiers with >= 2 active accounts.
Summary table of category, total_orders, total_gmv, and refund_rate_pct sorted by highest refund rate first.
Summary of department_name, total_admissions, avg_stay_days, and max_stay_days for wards with >= 2 admissions.
High-risk merchants with dispute rate >= 1.0%, sorted by highest dispute rate.
Delivery metrics per zone showing total packages, average transit time, and on-time percentage.
Department compensation metrics including min, max, avg, and wage spread, sorted by spread descending.
Plan tiers showing total events, unique active workspaces, and events per workspace.
Summary of promo code sales metrics with net revenue >= $500, sorted by highest net revenue.
Summary of pharmaceutical spending per drug category sorted by total cost.
High-volume ATMs requiring priority cash restocking, sorted by cash dispensed.
Summary of ride requests, completed rides, and completion percentage per vehicle tier.
Summary of lost MRR and churned accounts per industry sector with lost MRR >= $3,000.
Run queries directly in your browser against realistic tables.