视频图像处理系列索引 || Arcgis/Engine/Server开发索引 || Web Map Gis开发索引 || jquery表格组件 JQGrid索引
WPF MVVM模式开发实现简明教程索引 || ArcGIS Runtime WPF(.net C#)开发简明教程索引

Oracle以15分钟为界,统计一天内各时间段的数据笔数

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,

posted @ 2017-01-03 11:11  jhlong  阅读(1119)  评论(0编辑  收藏  举报
海龙的博客 jhlong@cnblogs 版权所有© 转载请注明链接.有用请推荐一下
代码全部经过本人测试,但不保证复制粘贴就正常运行,更不保证能解决你的问题,请结合前后代码及描述理解后修改和使用