Problem Statement
In PostgreSQL, which syntax cleanly aggregates only rows that match a condition without CASE?
Explanation
The FILTER clause applies a WHERE-like predicate to a single aggregate. It keeps the query readable when many conditional metrics are needed.
On engines without FILTER, use SUM(CASE WHEN ... THEN value ELSE 0 END).
Code Solution
SolutionRead Only
SELECT COUNT(*) AS orders, SUM(amount) FILTER (WHERE status='PAID') AS paid_amt FROM orders;
Practice Sets
This question appears in the following practice sets:
