oracle按时间分组统计的sql

上传人:xiao****1972 文档编号:84085536 上传时间:2019-03-02 格式:DOC 页数:4 大小:29.50KB
返回 下载 相关 举报
oracle按时间分组统计的sql_第1页
第1页 / 共4页
oracle按时间分组统计的sql_第2页
第2页 / 共4页
oracle按时间分组统计的sql_第3页
第3页 / 共4页
oracle按时间分组统计的sql_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《oracle按时间分组统计的sql》由会员分享,可在线阅读,更多相关《oracle按时间分组统计的sql(4页珍藏版)》请在金锄头文库上搜索。

1、Oracle按时间分组统计的sql如下表table1:日期(exportDate) 数量(amount)- -14-2月 -08 2010-3月 -08 214-4月 -08 614-6月 -08 7524-10月-09 2314-11月-09 4504-8月 -10 504-9月 -10 4404-10月-10 88注意:为了显示更直观,如下查询已皆按相应分组排序1.按年份分组select to_char(exportDate,yyyy),sum(amount) from table1 group by to_char(exportDate,yyyy);年份 数量-2009 682010 1

2、372008 1032.按月份分组select to_char(exportDate,yyyy-mm),sum(amount) from table1 group by to_char(exportDate,yyyy-mm)order by to_char(exportDate,yyyy-mm);月份 数量-2008-02 202008-03 22008-04 62008-06 752009-10 232009-11 452010-08 52010-09 442010-10 883.按季度分组select to_char(exportDate,yyyy-Q),sum(amount) from

3、table1 group by to_char(exportDate,yyyy-Q)order by to_char(exportDate,yyyy-Q);季度 数量-2008-1 222008-2 812009-4 682010-3 492010-4 884.按周分组select to_char(exportDate,yyyy-IW),sum(amount) from table1 group by to_char(exportDate,yyyy-IW)order by to_char(exportDate,yyyy-IW);周 数量-2008-07 202008-11 22008-16 6

4、2008-24 752009-43 232009-46 452010-31 52010-35 442010-40 88补充:按季度分组还有个比较笨的方法(参考网络资源)select to_char(exportDate,yyyy),sum(decode(to_char(exportDate,mm),01,amount,02,amount,03,amount,0) as 第一季,sum(decode(to_char(exportDate,mm),04,amount,05,amount,06,amount,0) as 第二季,sum(decode(to_char(exportDate,mm),07,amount,08,amount,09,amount,0) as 第三季,sum(decode(to_char(exportDate,mm),10,amount,11,amount,12,amount,0) as 第四季from table1group by to_char(exportDate,yyyy);年份 第一季 第二季 第三季 第四季-2009 0 0 0 682010 0 0 49 882008 22 81 0 0

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号