1、按年

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') SELECT trunc(sysdate-1) + (ROWNUM - 1) / 24 / 60 AS STAT_TIME
FROM DUAL d
CONNECT BY ROWNUM <= 1440 +(trunc(sysdate, 'MI') - (trunc(sysdate))) * 24 * 60

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
select STAT_TIME tdate,
'test' app_id,
goods_type, --c.col_4 as
goods_id, --c.col_5 as
goods_currency_type --c.col_6 as
from
(
SELECT trunc(sysdate-1) + (ROWNUM - 1) / 24 / 12 AS STAT_TIME
FROM DUAL d
CONNECT BY ROWNUM <= 288 +(trunc(sysdate, 'MI') - (trunc(sysdate))) * 24 * 12 + 1
),
(
select
t.goods_type,t.goods_id,t.goods_currency_type
from mid_minutes t
where tdate >= trunc(sysdate) -1
and app_id = 'test'
group by t.goods_type,t.goods_id,t.goods_currency_type
) c

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;

9、按半小时

select to_date(to_char(j.tdate, 'yyyy-mm-dd hh24:') || case
when to_char(j.tdate, 'mi') < '30' then
'00'
else
'30'
end,
'yyyy-mm-dd hh24:mi') as tdate,
j.goods_id,
sum(j.buy_count) as buy_count,
sum(j.total_price) as total_price
from tmp_goods_mis j
where j.tdate >= trunc(sysdate) - 1
group by j.goods_id
to_char(j.tdate, 'yyyy-mm-dd hh24:') || case
when to_char(j.tdate, 'mi') < '30' then
'00'
else
'30'
end

来源:https://www.cnblogs.com/linn/p/4186810.html

Oracle 按不同时间分组统计的更多相关文章

  1. Oracle按不同时间分组统计

    Oracle按不同时间分组统计 Oracle按不同时间分组统计的sql 如下表table1: 日期(exportDate) 数量(amount) -------------- ----------- ...

  2. ORACLE的分组统计之ROLLUP(一)

    Oracle 9i以后,扩展了group by 的功能,能够满足大部分多维数据的分析统计功能,主要表现: 1. rollup,cube,grouping sets 扩展group by字句提供了丰富的 ...

  3. Oracle Time Model Statistics(时间模型统计)

    Oracle数据库从10g開始,启用以时间模型统计为主.命中率为辅等性能度量指标.基于时间模型统计,主要是基于操作类型測量在数据库中花费的时间的统计信息.最重要的时间模型统计是数据库时间.或DB时间. ...

  4. Oracle数据库从入门到精通-分组统计查询

    视频课程:李兴华 Oracle从入门到精通 视频课程学习者:阳光罗诺 视频来源:51CTO学院 整体内容: 统计函数的使用 分组统计查询的实现 对分组的数据过滤 统计函数 在之前我们就学习过一个COU ...

  5. 010.简单查询、分组统计查询、多表连接查询(sql实例)

    -------------------------------------day3------------ --添加多行数据:------INSERT [INTO] 表名 [(列的列表)] --SEL ...

  6. Dev用于界面按选中列进行分组统计数据源(实用技巧)

    如果有用U8的可以明白这个功能就是模仿他的统计功能.我不过是把他造成通用的与适应于DEV的. (效率为6000条数据分组统计时间为3秒左右分组列过多5秒.1000条以下0.几秒,500条下0.00几秒 ...

  7. DataTable、List使用groupby进行分组和分组统计;List、DataTable查询筛选方法

    DataTable分组统计: .用两层循环计算,前提条件是数据已经按分组的列排好序的. DataTable dt = new DataTable(); dt.Columns.AddRange(new ...

  8. Mysql 根据时间戳按年月日分组统计

    Mysql 根据时间戳按年月日分组统计create_time时间格式SELECT DATE_FORMAT(create_time,'%Y%u') weeks,COUNT(id) COUNT FROM ...

  9. Mysql中较为复杂的分组统计去重复值

    这是我的代码: 前提是做了一个view:att_sumbase 首先分开统计每天的中午.下午饭点人数,这时需要分别去除中午和下午重复打卡的人.用了记录集的交,嵌套select的知识. 注意不能直接使用 ...

随机推荐

  1. 3. 站在使用层面,Bean Validation这些标准接口你需要烂熟于胸

    乔丹是我听过的篮球之神,科比是我亲眼见过的篮球之神.本文已被 https://www.yourbatman.cn 收录,里面一并有Spring技术栈.MyBatis.JVM.中间件等小而美的专栏供以免 ...

  2. VMware中卸载安装Ubuntu系统 ——Ubuntu系统配置(一)

    由于之前配置给Ubuntu的磁盘空间不足,进行了扩展磁盘空间,结果Ubuntu无法开机了,试了很多种办法都没成功,也有些后悔没有记录下配置过程,于是决定卸载Ubuntu进行重新安装和配置. 一.VMw ...

  3. 使用HttpUrlConnection访问www.163.com遇到503问题,用设置代理加以解决

    一次我使用如下程序连接到网易,意图获取其网站的html文本: try { String urlPath = "http://www.163.com/"; URL url = new ...

  4. 蓝奏网盘CMD控制台

    LanZouCloud-CMD 2.0 基于蓝奏云API开发的CMD版蓝奏云控制台 Github : https://github.com/zaxtyson/LanZouCloud-CMD 更新说明 ...

  5. IAR错误Error[e16]: Segment ISTACK (size: 0xc0 align: 0) is too long for segment definition. At least 0xd more bytes needed. The problem occurred while processing the segment 的解决办法

    IAR for 8051 IDE version 9.10.1编译阿莫单片机的cc2541程序osal第一节教程出现错误如下 出错的愿意是iar设置错误.所以需修改IAR的设置. 解决办法如下: 即可 ...

  6. JavaScript 异步编程

    博客地址:https://ainyi.com/96 众所周知,JavaScript 是单线程的,但异步在 js 中很常见,那么简单来介绍一下异步编程 同步编程和异步编程 同步编程,计算机一行一行按顺序 ...

  7. zookeeper服务端

    服务端启动时,就启动线程通过NIO监听网络端口.每个连接都会有一个上下文环境对象,当接收到请求后,会在上下文环境对象中进行处理. 服务端启动线程,监听网络端口,(NIOServerCnxn.Facto ...

  8. day56:django:csrf_token&文件上传

    目录 1.csrf介绍 2.django实现csrf_token认证 3.django实现文件上传 csrf介绍 什么是csrf? csrf:跨站请求伪造.攻击者通过HTTP请求将数据传送到服务器,从 ...

  9. NodeJS沙箱逃逸&&vm

    NodeJS沙箱逃逸 关于nodejs的沙箱 使用场景 在线代码编辑器 第三方js代码 jsonp,like百度搜索框 https://www.baidu.com/s?wd=nodejs&mi ...

  10. 2020 CiGA Game Jam活动总结

    CiGA Game Jam 总结 今年8月14.15.16号,48小时游戏开发--Game Jam开始了.蠢新第一次参加Game Jam,今年还是线上开展,情绪复杂= = 还有一个坏消息,晓航旅游缺席 ...