34,590
社区成员
发帖
与我相关
我的任务
分享
select CONVERT(CHAR(8), date, 8 ) as 时间段,
sum(value) as 平均值
from test_table
group by CONVERT(CHAR(8), date, 8 )
3、执行结果:
with t(Date,Value) as (
select cast('2016-03-23 00:05:00.000' as datetime),245833.0152000000union all
select '2016-03-23 00:10:00.000',150117.9056000000union all
select '2016-03-23 00:15:00.000',279134.5132500000union all
select '2016-03-23 00:20:00.000',146963.7195700000union all
select '2016-03-23 00:25:00.000',152732.6481400000union all
select '2016-03-23 00:30:00.000',136986.6713100000union all
select '2016-03-23 00:35:00.000',340922.0038000000union all
select '2016-03-23 00:40:00.000',263542.3197700000union all
select '2016-03-23 00:45:00.000',218160.9406900000union all
select '2016-03-23 00:50:00.000',150001.5314700000union all
select '2016-03-24 00:05:00.000',111111.0152000000union all
select '2016-03-24 00:10:00.000',222222.9056000000
)
select CONVERT(varchar(8),date,108) ,AVG(Value)
from t
group by CONVERT(varchar(8),date,108)