GROUP BY + SUM — the canonical pipeline roll-up query
Roll up the current book of business by stage. Sum the `amount` column, grouped by `stage`. Return all 7 stages with their total pipeline value. Order by total descending so the largest bucket is on top. Include Closed-Won and Closed-Lost too — I want to show the CRO the historical size of each bucket, not just open pipe.
| Column | Type | Key |
|---|---|---|
| opportunity_id | INT | PK |
| account_id | INT | FK → revops_accounts |
| owner_user_id | INT | FK → revops_users |
| name | TEXT | |
| stage | TEXT | |
| amount | REAL | |
| close_date | TEXT | |
| created_date | TEXT | |
| is_closed | INT | |
| is_won | INT |
Each hint you reveal reduces the XP you can earn. Try the query first.
Group by `stage`. SUM the amount. The ORDER BY references the alias or the SUM expression — either works.
You should see 7 rows — the same 7 distinct stages from mission 2, now with dollar totals next to them.
Don't filter anything out. The CRO asked for the full picture including Closed-Won and Closed-Lost — sometimes the biggest bucket of all is the lost one, and that's a signal.