Ah perfect. I was struggling with CASE outside the SUM(), which was not working.
---------------------------(end of broadcast)--------------------------- TIP 7: You can help support the PostgreSQL project by donating at http://www.postgresql.org/about/donate