34,838
社区成员




select
时间,sum(数量1) as 数量1,sum(数量2) as 数量2
from test group by 时间
/*
时间 数量1 数量2
----------- ----------- -----------
6 40 400
7 60 600
*/
select 时间,sum(数量1)as 数量1, sum(数量2)as 数量2
from test
group by 时间
declare @T table
(
时间 int,
数量1 int,
数量2 int
)
insert into @T select 6,10,100
insert into @T select 7,20,200
insert into @T select 6,30,300
insert into @T select 7,40,400
select * from @T
select t.时间,数量1=SUM(t.数量1),数量2=SUM(t.数量2)
from @T t group by t.时间
create table test
(
时间 int,
数量1 int,
数量2 int
)
insert into test select 6,10,100
insert into test select 7,20,200
insert into test select 6,30,300
insert into test select 7,40,400
select * from test
select 时间,sum(isnull(数量1,0))数量1,sum(isnull(数量2,0))数量2 from test
group by 时间
/*时间,数量1,数量2
6,40,400
7,60,600
(2 行受影响)
*/
drop table test