WHERE + COUNT to exclude a lifecycle bucket from a volume count
Quick QBR prep — the board pack needs a single 'total deals we worked this year' number. That's everything in `revops_opportunities` minus Closed-Lost (still-active pipeline plus deals we actually won). Counting Closed-Lost makes the bucket meaningless because dead deals shouldn't count as work-in-flight. Give me the count where `stage != 'Closed-Lost'`. Single number.
| 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 | |
| forecast_category | TEXT |
Each hint you reveal reduces the XP you can earn. Try the query first.
`stage != 'Closed-Lost'` is the filter. You could also write `stage <> 'Closed-Lost'` — same meaning.
`SELECT COUNT(*) FROM revops_opportunities WHERE stage != 'Closed-Lost'` gets you there. One row, one column.
If you're used to filtering lists of stages you might reach for `stage NOT IN ('Closed-Lost')` — same result for one-value lists, but spelled two ways for the same logic. Use whichever reads cleaner to your team.