我有一张表格,每30分钟写入一次值 我想计算几天内某个时间段内的平均值。
CREATE TABLE [dbo].[#TABLE_1](
[numreq] [int] NULL,
[rangetime] [nvarchar](300) NULL
) ON [PRIMARY]
insert into [dbo].[#TABLE_1] values('2','2019-03-10 12:00:00.000')
insert into [dbo].[#TABLE_1] values('3','2019-03-10 12:30:00.000')
insert into [dbo].[#TABLE_1] values('4','2019-03-10 13:00:00.000')
insert into [dbo].[#TABLE_1] values('5','2019-03-10 13:30:00.000')
insert into [dbo].[#TABLE_1] values('6','2019-03-11 12:00:00.000')
insert into [dbo].[#TABLE_1] values('7','2019-03-11 12:30:00.000')
insert into [dbo].[#TABLE_1] values('8','2019-03-11 13:00:00.000')
insert into [dbo].[#TABLE_1] values('9','2019-03-11 13:30:00.000')
我写了一个sql查询,但是没有给出想要的结果
select avg([numreq]),[rangetime]
from [dbo].[#TABLE_1]
group by [rangetime]
我想要得到的结果:
numreq rangetime
4 12:00
5 12:30
6 13:00
7 13:30