Filtered Inside The Group
Table orders:
| id | cust | amount | status |
|---|---|---|---|
| 1 | A | 100 | paid |
| 2 | A | 50 | refunded |
| 3 | B | 200 | paid |
| 4 | B | 300 | refunded |
| 5 | C | 75 | paid |
SELECT cust, sum(amount) AS total
FROM orders
GROUP BY cust
HAVING sum(amount) FILTER (WHERE status = 'paid') >= 100;
What does this return?
Sign in to answer questions and track your progress
Sign In