17,377
社区成员
发帖
与我相关
我的任务
分享
select t3.id,to_char(t3.time1,'yyyy-MM-dd'),
count(case when t3.button='1' then 1 end) a1,
count(case when t3.button='2' then 2 end) a2,
count(case when t3.button='3' then 3 end) a3,
count(case when t3.button='' then 4 end) a4
from table1 )
) t3 group by to_char(t3.time1,'yyyy-MM-dd'),id
您好,再请问下上面这个,table1还有个字段是cs,实际是在统计button为3时,如果table1中cs字段和button为3的数据的cs字段值相同并且button相同则取一条,否则不统计,
假设表中button为3的数据有一条,它的cs值为111,而cs值为111的数据在table1中总共有5条,如果这5条的button都为3就统计为1条数据,否则不统计,请问该怎么写呢
select xb,xl,sum(decode(xb,'男',1,cnt)) as cnt
from(select xb,xl,count(id) as cnt from 表名称 group by xb,xl)
group by xb,xl;