Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumSQLpivot conditional aggregationSingle-choice MCQ

You build a pivot of monthly counts using FILTER. What does the FILTER clause do that a plain CASE-inside-aggregate cannot express more cleanly?

SELECT COUNT(*) FILTER (WHERE status = 'open') AS open_cnt, COUNT(*) FILTER (WHERE status = 'closed') AS closed_cnt, AVG(amount) FILTER (WHERE status = 'open') AS avg_open FROM tickets;