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. SpringCloud入门 消息总线 Bus

    消息总线 1.概述 使用SpringCloud Bus配和Spring Cloud Config使用实现配置的动态刷新 Bus只支持消息处理:RabbitMQ和Kafaka. 能干嘛 能管理和传播分布 ...

  2. Cypress系列(44)- 命令行运行 Cypress

    如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 前面也介绍过 Cypress 命令 ...

  3. npm 进阶命令知多少(一)

    npm命令知多少(一) 前言 作为前端模块化扎展现形式的npm包,已经在前端开发中不可或缺,熟练掌握npm相关内容,也是前端开发者的一门必修课,那么除了npm publish这类常见内容之外,还有哪些 ...

  4. HTTP走私

    干货 https://paper.seebug.org/1048/

  5. 原生js实现jquery的siblings()

    Element.prototype.siblings = function(callback){ var siblingElement = []; var parentAllElement = []; ...

  6. White Bird(AOJ 2308)

    原题如下: Angry Birds is a mobile game of a big craze all over the world. You were convinced that it was ...

  7. 架构设计 | 基于Seata中间件,微服务模式下事务管理

    源码地址:GitHub·点这里 || GitEE·点这里 一.Seata简介 1.Seata组件 Seata是一款开源的分布式事务解决方案,致力于提供高性能和简单易用的分布式事务服务.Seata将为用 ...

  8. 软件定义网络(SDN)第二次实验报告

    目录 实验 2 :Mininet 实验--拓扑的命令脚本生成 一.实验目的 二.实验任务 三.实验要求 四.具体实验步骤 引导实验 Part 1 引导实验 Part 2 本周实验任务完成流程 五.注意 ...

  9. myBatis源码解析-二级缓存的实现方式

    1. 前言 前面近一个月去写自己的mybatis框架了,对mybatis源码分析止步不前,此文继续前面的文章.开始分析mybatis一,二级缓存的实现.附上自己的项目github地址:https:// ...

  10. ava实现时钟小程序【代码】

    其实这个程序并不难,主要是用Java 2D画图,弄一个线程,每隔一秒,依照时针分针秒针各自的速度重新计算它们走过的角度(相对12点方向顺时针偏离的角度),利用这个角度算出它们各自端点的坐标,重绘一次表 ...