统计问题
下面是一个典型的统计sql语句
select
sum(case when condition1=true then 1 else 0 end) as size1,
sum(case when condition2=true then 1 else 0 end) as size2,
sum(case when condition3=true then 1 else 0 end) as size3,
sum(case when condition4=true then 1 else 0 end) as size4,
sum(case when condition5=true then 1 else 0 end) as size5,
sum(case when condition6=true then 1 else 0 end) as size6,
sum(case when condition7=true then 1 else 0 end) as size7,
sum(case when condition8=true then 1 else 0 end) as size8,
sum(case when condition9=true then 1 else 0 end) as size9,
sum(case when condition10=true then 1 else 0 end) as size10
from tables
where ...
如果这时候我想增加一个统计项目size11,他的条件是以上condition1-condition10都不成立。即sum(case (conditon1=false and condition2=false ... and condition10=false) then 1 else 0 end) as size11。
但是这样写不论是这个sql语句的大小、效率都不会让人满意(我有condition50或更多的情况呢),希望得到大家的指点。