Oracle按不同时间分组统计
2014-12-26 15:00
183 查看
1、按年
2、按月
3、按季
4、按周
5、按小时
6、按分钟
7、按5分钟
8、按十分钟
按5分钟统计,把时间转换成分钟准点函数
select to_char(record_date,'yyyy'), sum(col_8) as total_money from table_name where group by to_char(record_date,'yyyy')
2、按月
select to_char(record_date,'yyyy-mm'), sum(col_8) as total_money from table_name where group by to_char(record_date,'yyyy-mm')
3、按季
select to_char(record_date,'yyyy-Q'), sum(col_8) as total_money from table_name where group by to_char(record_date,'yyyy-Q')
4、按周
select to_char(record_date,'yyyy-IW'), sum(col_8) as total_money from table_name where group by to_char(record_date,'yyyy-IW')
5、按小时
select to_char(record_date,'yyyy-mm-dd hh24'), sum(col_8) as total_money from table_name where group by to_char(record_date,'yyyy-mm-dd hh24')
6、按分钟
select to_char(record_date,'yyyy-mm-dd hh24:mi'), sum(col_8) as total_money from table_name where group by to_char(record_date,'yyyy-mm-dd hh24:mi')
7、按5分钟
SELECT trunc(sysdate) + (ROWNUM - 1) / 24/12 AS STAT_TIME FROM DUAL CONNECT BY ROWNUM <=(trunc(sysdate, 'MI') - (trunc(sysdate))) * 24 * 12
按5分钟统计,中间没数据的时间会缺少 select to_char(j.record_date,'yyyymmdd') as st_date , sum(j.col_8*j.col_9*j.col_10) as mer_value , to_char(j.record_date,'hh24') as STAT_HOUR , floor(to_char(j.record_date,'mi')/5) as min_flag , '昨日' as report_name from c , j where c.col_4 = j.col_4 and c.col_5 = j.col_5 and c.col_6 = j.col_6 and j.actiontype = 217 and j.record_date between trunc(sysdate-1) and trunc(sysdate) group by to_char(j.record_date,'yyyymmdd'), to_char(j.record_date,'hh24'), floor(to_char(j.record_date,'mi')/5) ORDER BY st_date, STAT_HOUR, min_flag
8、按十分钟
SELECT trunc(sysdate) + (ROWNUM - 1) / 24/6 AS STAT_TIME FROM DUAL CONNECT BY ROWNUM <=(trunc(sysdate, 'MI') - (trunc(sysdate))) * 24 * 6
按5分钟统计,把时间转换成分钟准点函数
create or replace function trunc_minute(v_date date) return date as begin return to_number(trunc(to_char(v_date, 'mi')/5))*5/(24*60) + trunc(v_date, 'hh24'); end;
相关文章推荐
- Oracle按不同时间分组统计
- Oracle按不同时间分组统计
- Oracle按时间分组统计的sql与oracle 多行合并一行
- mysql date_format 按不同时间单位进行分组统计
- oracle 按照时间分组统计求和
- oracle 按时间分组统计
- mysql date_format 按不同时间单位进行分组统计
- oracle 数据统计 按时间汇总
- oracle小记1--分组 排序 取最新时间记录
- Oracle 按时间段分组统计
- oracle分组统计sql
- Oracle中时间处理及分时间段统计
- oracle 统计操作 分组统计
- 一段oracle中的“复杂”分组统计sql
- oracle 分组统计后结果相减-----实例
- Oracle 按时间段分组统计
- SQL Server中按照时间进行分组统计
- Oracle按时间段分组统计
- Oracle之组函数及分组统计(重点)
- Oracle学习(4)组函数和分组统计