select t_time,o_value=avg(o_value)
from(
select t_time=dateadd(minute,
datediff(minute,convert(char(10),t_time,120),t_time)/5, --5分钟,是30分钟的话,将5改为30
convert(char(10),t_time,120)),
o_value
from A
where o_state in('Z','A') --Z,A的时候才统计
)a group by t_time
from(
select t_time=dateadd(minute,
datediff(minute,convert(char(10),t_time,120),t_time)/5, --5分钟,是30分钟的话,将5改为30
convert(char(10),t_time,120)),
o_value
from A
where o_state in('Z','A') --Z,A的时候才统计
)a group by t_time
你的想法有点明白了,但是你这个实现好象还是不正确
select t_time=dateadd(minute,
datediff(minute,convert(char(10),t_time,120),t_time)/5, --5分钟,是30分钟的话,将5改为30
convert(char(10),t_time,120)),
o_value
from A
where o_state in('Z','A') --Z,A的时候才统计应该改为:
select t_time=dateadd(minute,
datediff(minute,convert(char(10),t_time,120),t_time)%5, --5分钟,是30分钟的话,将5改为30
convert(char(16),t_time,120)),
o_value
from A
where o_state in('Z','A') --Z,A的时候才统计