SQL (DB2) Return multiple conditional counts in a single query
db2, sql
Solution
This will count the occurrence of each condition:
select sum(case when t1.a = 1 then 1 else 0 end) as A_COUNT
, sum(case when t1.b = 2 then 1 else 0 end) as B_COUNT
from t1
where t1.a = 1
or t1.b = 2
Problem
I am trying select multiple conditional summaries into a single table result on a DB2 based database. Example: ``` SELECT COUNT(FOO) FROM T1 WHERE T1.A=1 AS A_COUNT, SELECT COUNT(FOO) FROM T1 WHERE T1.B=2 AS B_COUNT Ext... ``` Any help is appreciated.