Oracle 查询今天、昨天、本周、上周、本月、上月数据

查询今天数据:

SELECT COUNT(1) FROM T_CALL_RECORDS WHERE TO_CHAR(T_RKSJ,’YYYY-MM-DD’)=TO_CHAR(SYSDATE,’YYYY-MM-DD’);

查询昨天数据:

SELECT COUNT(1) FROM T_CALL_RECORDS WHERE TO_CHAR(T_RKSJ,’YYYY-MM-DD’)=TO_CHAR(SYSDATE-1,’YYYY-MM-DD’);

查询本周数据:

SELECT COUNT(1) FROM T_CALL_RECORDS WHERE T_RKSJ >= TRUNC(NEXT_DAY(SYSDATE-8,1)+1) AND T_RKSJ < TRUNC(NEXT_DAY(SYSDATE-8,1)+7)+1;

查询上周数据:

SELECT COUNT(1) FROM T_CALL_RECORDS WHERE T_RKSJ >= TRUNC(NEXT_DAY(SYSDATE-8,1)-6) AND T_RKSJ < TRUNC(NEXT_DAY(SYSDATE-8,1)+1);

查询本月数据:

SELECT COUNT(1) FROM T_CALL_RECORDS WHERE TO_CHAR(T_RKSJ,’YYYY-MM’)=TO_CHAR(SYSDATE,’YYYY-MM’);

查询上月数据:

SELECT COUNT(1) FROM T_CALL_RECORDS WHERE TO_CHAR(T_RKSJ,’YYYY-MM’)=TO_CHAR(ADD_MONTHS(SYSDATE,-1),’YYYY-MM’);

作者:Jeebiz  创建时间:2023-01-11 11:32
最后编辑:Jeebiz  更新时间:2024-08-22 10:22