oracle按天,周,月,季度,年查询排序
天--to_char(t.start_time,'YYYY-MM-DD') 周 --to_char(t.start_time,'YYYY'),to_char(t.start_time,'IW') 月度--to_char(t.start_time,'YYYY-MM') 季度--to_char(t.start_time,'YYYY'),to_char(t.start_time,'Q') 年度--to_char(t.start_time,'YYYY')
按天查询
select to_char(t.start_time,'YYYY-MM-DD') day ,count(*) from test t where to_char(t.start_time,'YYYY')='2019' --条件限制 group by to_char(t.start_time,'YYYY-MM-DD') --分组 order by to_char(t.start_time,'YYYY-MM-DD') --排序
按周查询
select to_char(t.start_time,'YYYY') year ,to_char(t.start_time,'IW'),count(*) from test t where to_char(t.start_time,'YYYY')='2019' --条件限制 group by to_char(t.start_time,'YYYY') year ,to_char(t.start_time,'IW')--分组 order by to_char(t.start_time,'YYYY') year,to_char(t.start_time,'IW') --排序
按月度查询
select to_char(t.start_time,'YYYY-MM') ,count(*) from test t where to_char(t.start_time,'YYYY')='2019' --条件限制 group by to_char(t.start_time,'YYYY-MM') --分组 order byto_char(t.start_time,'YYYY-MM') --排序
按季度查询
select to_char(t.start_time,'YYYY') year ,to_char(t.start_time,'Q'),count(*) from test t where to_char(t.start_time,'YYYY')='2019' --条件限制 group by to_char(t.start_time,'YYYY') ,to_char(t.start_time,'Q')--分组 order byto_char(t.start_time,'YYYY') ,to_char(t.start_time,'Q')--排序
按年度查询
select to_char(t.start_time,'YYYY') year ,count(*) from test t where to_char(t.start_time,'YYYY')='2019' --条件限制 group by to_char(t.start_time,'YYYY') --分组 order by to_char(t.start_time,'YYYY') --排序
知识点扩展:oracle 实现按天,周,月,季度,年查询统计数据
这里提供了一种方法,挺不错oracle 实现按周,月,季度,年查询统计数据 。
还在网上看到用trunc来搞也可以,下面是个例子,两句SQL效果一样的.
id有重复的,所以group by搞了两个字段.
只在Oracle数据库里试过,其它库没试过。
create table CONSUMER_ACC ( ID VARCHAR2(50) not null , ACC_NUM VARCHAR2(10), DATETIME DATE ) select t.id,trunc(t.datetime, 'mm' ) as d, sum (t.acc_num) as n from CONSUMER_ACC t --where group by t.id,trunc(t.datetime, 'mm' ) order by n desc ; select t.id,to_char(t.datetime, 'mm' ) d , sum (t.acc_num) n from CONSUMER_ACC t --where group by t.id,to_char(t.datetime, 'mm' ) order by n desc ------------------------------------------------------------------------------ //按天统计 select count(dataid) as 每天操作数量, sum() from where group by trunc(createtime, 'DD')) //按自然周统计 select to_char(date,'iw'),sum() from where group by to_char(date,'iw') //按自然月统计 select to_char(date,'mm'),sum() from where group by to_char(date,'mm') //按季统计 select to_char(date,'q'),sum() from where group by to_char(date,'q') //按年统计 select to_char(date,'yyyy'),sum() from where group by to_char(date,'yyyy')
总结
以上所述是小编给大家介绍的oracle实现按天,周,月,季度,年查询排序方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对小牛知识库网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
我想从Oracle中的sql日期中找到四分之一周。 我尝试在下面的查询中查找年份、季度和周。但week字段给出的是“每月的一周”,而不是“季度的一周” 选择to_char(sysdate,'YYYY')|| '-Q'||to_char(sysdate,'Q') || '-W'|| 上述查询返回“2016-Q2-W3”,因为日期位于当月的第三周。 假设sysdate是2016年6月17日,我期待结果
问题内容: 是否可以通过简单的查询来计算在一个确定的时间段(例如年,月或日)中有字段的记录数,例如: 甚至: 具有每月统计信息。 谢谢! 问题答案: 在MySQL中检查日期和时间函数。
当运行下面的查询时,我试图找到一种方法来按联邦财政年度显示返回的月份,而不是正常的顺序值。 (我想按以下顺序显示月份:10月、11月、12月、1月、2月、3月、4月、5月、6月、7月、8月、9月,而不是1月至12月)谢谢
本文向大家介绍php实现按天数、星期、月份查询的搜索框,包括了php实现按天数、星期、月份查询的搜索框的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了php实现按天数、星期、月份查询的搜索框,搜索时候展示数据的统计图,主要展示图形的效果,供大家参考,具体内容如下 1.ajax.php 2.datehelper.php 3.statistics.php 4.theline.php
这就是我所拥有的。
问题内容: 因此,我有一个表,其ID值和日期看起来像这样: 基本上,ID值仅对那一年是唯一的-它们会重置下一年。 我希望能够按ID值和日期排序,但我想进行排序,以便按年份对值进行排序。只是带有辅助日期排序的常规ID会产生以下结果: 但是我想要一个查询,该查询生成一个看起来像这样的表: 这可能吗? 问题答案: 这个怎么样:
本文向大家介绍Java Map 按key排序和按Value排序的实现方法,包括了Java Map 按key排序和按Value排序的实现方法的使用技巧和注意事项,需要的朋友参考一下 一、理论准备 Map是键值对的集合接口,它的实现类主要包括:HashMap,TreeMap,Hashtable以及LinkedHashMap等。 TreeMap:基于红黑树(Red-Black tree)的 Naviga