oracle实现动态查询前一天早八点到当天早八点的数据功能示例

来自:互联网
时间:2021-01-09
阅读:
免费资源网,https://freexyz.cn/

本文实例讲述了oracle实现动态查询前一天早八点到当天早八点的数据。分享给大家供大家参考,具体如下:

需要查询前一天早八点到当天早八点的数据

这里是查询sql语句

SELECT
  DEPT_ID,
  COUNT( * ) DID
FROM
  "MES_MACH_CALL_EVENT"
WHERE
  CALL_TIME >= trunc(sysdate-1)+8/24
  AND CALL_TIME <= trunc(sysdate)+8/24
GROUP BY
  DEPT_ID

现在单独来看一下获取系统当天八点和前一天八点的方法

SELECT trunc(sysdate)+8/24 FROM DUAL;
SELECT trunc(sysdate-1)+8/24 FROM DUAL;

+8/24为24小时制中的早八点

其中trunc函数的用法为

【trunc(for dates)】TRUNC()函数处理日期

语法格式:TRUNC(date[,fmt])

其中:date 一个日期值;fmt 日期格式。

该日期将按指定的日期格式截取;忽略它则由最近的日期截取。

示例:

select trunc(sysdate) from dual;–2017/2/13,返回当前时间 
select trunc(sysdate,'yy') from dual;–2017/1/1,返回当年第一天 
select trunc(sysdate,'mm') from dual;–2017/2/1,返回当月的第一天 
select trunc(sysdate,'d') from dual;–2017/2/12,返回当前星期的第一天,即星期天 
select trunc(sysdate,'dd') from dual;–2017/2/13,返回当前日期,今天是2017/2/13 
select trunc(sysdate ,'HH24') from dual;–2017/2/13 15:00:00,返回本小时的开始时间 
select trunc(sysdate ,'MI') from dual;–2017/2/13 15:13:00,返回本分钟的开始时间
免费资源网,https://freexyz.cn/
返回顶部
顶部