Is it possible to use the result of SUM in a case? My current query is like this:
SELECT USERNAME, SUM(AMOUNT),
CASE SUM(AMOUNT)
WHEN SUM(AMOUNT) = 0.0 THEN 1
WHEN SUM(AMOUNT) < 50.0 THEN 2
WHEN SUM(AMOUNT) > 75.0 THEN 4
END AS gid, 0 FROM payments GROUP BY USERNAME;
That looks fine to me, but generates this:
censored 13.00 NULL 0
Is it even possible to do that?