oracle按天,周,月,季度,年查询排序

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,‘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‘),‘IW‘)--分组
order by to_char(t.start_time,‘IW‘) --排序

按月度查询

select to_char(t.start_time,‘YYYY-MM‘),‘YYYY-MM‘) --分组
order byto_char(t.start_time,‘YYYY-MM‘) --排序

按季度查询

select to_char(t.start_time,‘Q‘),‘YYYY‘),‘Q‘)--分组
order byto_char(t.start_time,‘Q‘)--排序

按年度查询

select to_char(t.start_time,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‘) --排序

相关文章

文章浏览阅读773次,点赞6次,收藏9次。【代码】c# json字符...
文章浏览阅读8.7k次,点赞2次,收藏17次。此现象一般定位到远...
文章浏览阅读2.8k次。mysql脚本转化为oracle脚本_mysql建表语...
文章浏览阅读2.2k次。cx_Oracle报错:cx_Oracle DatabaseErr...
文章浏览阅读1.1k次,点赞38次,收藏35次。本文深入探讨了Or...
文章浏览阅读1.5k次。默认自动收集统计信息的时间为晚上10点...