table 里有两个字段:vv,time
time的格式为2008-1-1 0:05:00,但是我想把vv按小时统计,所以加了一个辅助字段;time2,然后:
update table set time2=round(time,''HH24'')
然后把统计值插入新表table2
insert into table2 (vvv,Time) select sum(vv),time2 from table group by time2
结果统计出来的值是以每个小时25分钟为分界线的!而time2的格式是对的,请教各位大侠是为什么啊?这种每个小时的统计该怎么做啊?
time的格式为2008-1-1 0:05:00,但是我想把vv按小时统计,所以加了一个辅助字段;time2,然后:
update table set time2=round(time,''HH24'')
然后把统计值插入新表table2
insert into table2 (vvv,Time) select sum(vv),time2 from table group by time2
结果统计出来的值是以每个小时25分钟为分界线的!而time2的格式是对的,请教各位大侠是为什么啊?这种每个小时的统计该怎么做啊?
select sum(vv),to_char(time,'hh24')
from table
group by to_char(time,'hh24')
这句什么意思啊?
是每25分钟为单位,还是一小时25分钟(85分钟)为单位?
你用round其实是问题的,round是四舍五入的,
粗略的说,
比如1:20和1:40,用round的话,出来就是1:00和2:00
所以建议用trunc比较好
所以你要插入DATE型的,可以这样
insert into table2 (vvv,Time)
select sum(vv),trunc(time,'hh24') from table group by trunc(time,'hh24')