9i:select col1
,sum(case when col2=1 then 1 else 0 end) count1
,sum(case when col2=2 then 1 else 0 end) count2
,sum(case when col2=3 then 1 else 0 end) count3
from a group by col18i:select col1
,sum(decode(col2,1,1,0)) count1
,sum(decode(col2,2,1,0)) count2
,sum(decode(col2,3,1,0)) count3
from a group by col1
,sum(case when col2=1 then 1 else 0 end) count1
,sum(case when col2=2 then 1 else 0 end) count2
,sum(case when col2=3 then 1 else 0 end) count3
from a group by col18i:select col1
,sum(decode(col2,1,1,0)) count1
,sum(decode(col2,2,1,0)) count2
,sum(decode(col2,3,1,0)) count3
from a group by col1
select col1, count(case 用户种类 when '1' then 1 else 0) ,
count(case 用户种类 when '1' then 1 else 0),
count(case 用户种类 when '1' then 1 else 0) from a group by col1
但我现在实际用的表比这个要复杂一些,每个统计列的条件还要多得多,比如某列统计数加上时间的限制,某列要连接到另外一个表,我要如何把这些条件加到里面去?
例如,此表要多两个字段,col4 帐号,col5集团种类
查询结果集的第二列要增加一个条件,帐号在另外一个表b中,怎么实现
还有,DECODE可以对对几个字段进行判断吗?比如,结果集第三列要增加集团种类的判断,集团号为0的才统计进来,怎么实现?
不好意思,是我开始没把问题写清楚,拜托高手再给我解决一下,在线等