Problem Statement
Portable way to count only paid orders in a window when FILTER clause is unavailable?
Explanation
CASE inside SUM is widely supported and yields a conditional count. FILTER is elegant where supported, but not universal across engines.
This pattern also works for conditional sums and averages by returning the numeric to aggregate or zero.
Code Solution
SolutionRead Only
SUM(CASE WHEN status='PAID' THEN 1 ELSE 0 END) OVER (PARTITION BY customer_id) AS paid_cnt
