我正在尝试将多个条件摘要选择到基于DB2的数据库上的单个表结果中.
例:
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...
任何帮助表示赞赏.
解决方法
这将计算每个条件的发生:
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