oracle实现按天,周,月,季度,年查询排序方法
发表于:2024-09-25 作者:千家信息网编辑
千家信息网最后更新 2024年09月25日,oracle按天,周,月,季度,年查询排序天--to_char(t.start_time,'YYYY-MM-DD')周 --to_char(t.start_time,'YYYY'),to_char(t
千家信息网最后更新 2024年09月25日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,'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实现按天,周,月,季度,年查询排序方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
查询
排序
统计
季度
条件
分组
限制
数据
方法
年度
月度
统计数据
自然
帮助
不错
两个
例子
出处
字段
效果
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
cej杂志是哪个数据库
服务器不管理
数据库同步实施方案
数据库换码字符转义字符
教我画网络安全手抄报图片
服务器安全狗添加信任
计算机网络技术高一课程
彩虹六号如何改服务器
反诈骗网络安全组织
什么是数据库客户端
Pg数据库中两个结果集想剪
天津移动网络技术类工资
软件开发常用证书
寻宝天行网络技术是真的吗
王者体验服服务器为什么没有响
软件开发员真诚征婚
招聘会 软件开发 专科
sybase数据库介绍
ice服务器跑酷大神
软件开发立项申请去哪个部门
找不到radius服务器
怎么打开金蝶的数据库
河北正规软件开发公司
云服务器管理终端在哪看
湖北省网络安全中心主任
国家网络安全技术发展战略
中小学学校网络安全教案
实况数据库小程序叫什么
万德数据库可以导出资产负债表吗
申通快递无法连接服务器