Oracle 数据库统计本年、本月、 本周的数据

本文提供了一种使用SQL查询来获取指定数据表中本周、本月及本年的数据记录总数的方法,通过具体的时间条件筛选实现了对不同时间跨度的数据统计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 本周
    select count(*) from 表 where time > sysdate - (to_char(sysdate-1,’D’))
    其中,time为数据表中的时间对应字段

–本周申请总数
select count(*) from lzcity_approve_control_info where begin_date > sysdate - (to_char(sysdate-1,’D’));

  • 本月
    select count(*) from 表 where time>=TRUNC(SYSDATE, ‘MM’) and time<=last_day(SYSDATE)
    其中,time为数据表中的时间对应字段

–本月申请数
select count(*) from lzcity_approve_control_info where begin_date>=TRUNC(SYSDATE, ‘MM’) and begin_date<=last_day(SYSDATE);

  • 本年
    select count(*) from 表 where to_char(time,’yyyy’)=to_char(sysdate,’yyyy’)
    其中,time为数据表中的时间对应字段

–今年申请数
select count(*) from lzcity_approve_control_info where to_char(begin_date,’yyyy’)=to_char(sysdate,’yyyy’);

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值