现有表数据 日期 参数1 参数22010-06-11 1 1
2010-06-11 1 0
2010-06-11 0 0
2010-06-10 0 1
2010-06-10 0 1
2010-06-11 1 0
2010-06-10 0 1
求用SQL查询后。得出以下结果
日期 参数1为1的总数 参数2为1总数
2010-06-10 0 3
2010-06-11 3 1求大虾指教
2010-06-11 1 0
2010-06-11 0 0
2010-06-10 0 1
2010-06-10 0 1
2010-06-11 1 0
2010-06-10 0 1
求用SQL查询后。得出以下结果
日期 参数1为1的总数 参数2为1总数
2010-06-10 0 3
2010-06-11 3 1求大虾指教
sum(case when 参数1=1 then 1 else 0 end) as [参数1为1的总数],
sum(case when 参数2=1 then 1 else 0 end) as [参数2为1的总数]
from tb
group by 日期
不好意思,上面那句话写错了,我多插入了一行,抱歉create table time_test
(
shijian datetime,
canshu1 int,
canshu2 int
)insert into time_test values('2010-06-11',1,1)
insert into time_test values('2010-06-11',1,0)
insert into time_test values('2010-06-11',0,0)
insert into time_test values('2010-06-10',0,1)
insert into time_test values('2010-06-10',0,1)
insert into time_test values('2010-06-11',1,0)
insert into time_test values('2010-06-10',0,1)select convert(char(10),shijian,120),
sum(canshu1) '参数1的总和',sum(canshu2) '参数2的总和'
from time_test
group by convert(char(10),shijian,120)
感觉着对的
select 日期,sum(参数1),sum(参数2)
group by 日期
select 日期,sum(参数1),sum(参数2)
from table
group by 日期
from table1