zoukankan      html  css  js  c++  java
  • 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,

  • 相关阅读:
    移动互联网整理笔记(这课内容太多了。。。)
    11.19
    hihoCoder#1879 : Rikka with Triangles (计算几何)
    hdu 4758 (AC自动机)
    hdu 4511 (AC自动机)
    2018 icpc 青岛
    hdu 6219 Empty Convex Polygons (凸包)
    2019 ccpc 秦皇岛
    2018 icpc 徐州
    hdu6599 I Love Palindrome String
  • 原文地址:https://www.cnblogs.com/jhlong/p/6244156.html
Copyright © 2011-2022 走看看