我有一个表
编号 时间 方量
001 2010-01-01 08:01:01 7
002 2010-01-01 08:20:01 5
003 2010-01-01 09:11:56 12
004 2010-01-01 10:20:01 5
005 2010-01-01 11:20:01 5用什么语句得到以下结果8点 129点 1210点 5
11点 5就是按时间段统计
编号 时间 方量
001 2010-01-01 08:01:01 7
002 2010-01-01 08:20:01 5
003 2010-01-01 09:11:56 12
004 2010-01-01 10:20:01 5
005 2010-01-01 11:20:01 5用什么语句得到以下结果8点 129点 1210点 5
11点 5就是按时间段统计
insert into tb select '001','2010-01-01 08:01:01',7
insert into tb select '002','2010-01-01 08:20:01',5
insert into tb select '003','2010-01-01 09:11:56',12
insert into tb select '004','2010-01-01 10:20:01',5
insert into tb select '005','2010-01-01 11:20:01',5
go
select datepart(hh,时间),sum(方量) from tb group by datepart(hh,时间)
go
drop table tb
/*
----------- -----------
8 12
9 12
10 5
11 5(4 行受影响)*/
insert into tb select '001','2010-01-01 08:01:01',7
insert into tb select '002','2010-01-01 08:20:01',5
insert into tb select '003','2010-01-01 09:11:56',12
insert into tb select '004','2010-01-01 10:20:01',5
insert into tb select '005','2010-01-01 11:20:01',5
go
select convert(varchar,datepart(hh,时间))+'点',sum(方量) from tb group by datepart(hh,时间)
go
drop table tb
/*
----------- -----------
8点 12
9点 12
10点 5
11点 5
(4 行受影响)*/