string sql = "select to_char(StartTime, 'yyyy')||'-'|| to_char(StartTime, 'mm')||'-'||
to_char(StartTime, 'dd')||' '|| to_char(StartTime, 'hh24')||':'||
floor(to_char(StartTime, 'mi')/15)*15 statime, sum(Count) as Counts from
table where StartTime <= to_date('2016-11-29 18:00:00' ,'YYYY-MM-DD hh24:mi:ss')
group by to_char(StartTime, 'yyyy')||'-'|| to_char(StartTime, 'mm')||'-'||
to_char(StartTime, 'dd')||' '|| to_char(StartTime, 'hh24')||':'||
floor(to_char(StartTime, 'mi')/15)*15 order by statime";
string sql = "select to_char(StartTime, 'yyyy')||'-'|| to_char(StartTime, 'mm')||'-'||" + "to_char(StartTime, 'dd')||' '|| to_char(StartTime, 'hh24')||':'|| " + "floor(to_char(StartTime, 'mi')/15)*15 statime, sum(Count) as Counts" + " from table " + "where StartTime <= to_date('2016-11-29 18:00:00' ,'YYYY-MM-DD hh24:mi:ss') " + "group by to_char(StartTime, 'yyyy')||'-'|| " + "to_char(StartTime, 'mm')||'-'|| to_char(StartTime, 'dd')||' '|| " + "to_char(StartTime, 'hh24')||':'|| floor(to_char(StartTime, 'mi')/15)*15 order by statime";
如上sql语句
StartTime是其中的时间字段
Count是汇总的字段,也可以count(*)统计记录数
table是表名,自己替换
也可以把15改成30,60等等需要统计汇总的分钟数
同理,按天统计可以修改条件如下,按月年或其他都一样
to_char(StartTime , 'yyyy')||'-'|| to_char(StartTime , 'mm')||'-'||
floor(to_char(StartTime , 'dd')/1)*1 sj,