Reputation: 7
I have:
SELECT
SUM(X) AS columnA,
CASE WHEN Y = TRUE THEN 'VAR' ELSE 'VAR2' END
Then I group by to get the counts but how do I sum X when Y is TRUE only? Or get the % of A in relation to true/untrue?
Upvotes: 0
Views: 5331
Reputation: 173046
how do I sum X when Y is TRUE only?
SELECT SUM(CASE WHEN Y = TRUE THEN X ELSE 0 END)
Upvotes: 1