【问题标题】:Select specific timestamp interval across multiple dates选择跨多个日期的特定时间戳间隔
【发布时间】:2014-11-15 01:04:12
【问题描述】:

我曾尝试在 Google 和其他各种网站上进行搜索,但都没有成功,甚至使搜索词尽可能模糊。

我有一个跨多天的数据查询,但我只想选择时间在 21:45 到 22:45 之间的数据。

我认为,使用整个数据构建的临时表具有从 to_date 转换为 to_char 的数据列,因此有必要将其更改回 to_date 或 to_timestamp。

问题是我已经尝试了这两种方法并且得到了无效的月份错误。例如 to_date(complete_date, 'hh24:mi:ss') 给了我错误。

我不确定如何在不提供硬编码日期的情况下过滤时间戳间隔。

提前非常感谢。我正在使用 Oracle Sql,不幸的是我目前没有查询。它在工作的电脑上。如果收到回复并且我正在工作,我可以回复更多信息。

With details as (
      select to_char(complete_date, 'yyyy-mm-dd hh24:mi:ss') complete_date, 
             to_char(complete_date, 'hh24:mi:ss') as ts from table 
      where complete_date between trunc(sysdate)-30 and trunc(sysdate) )

select * from details where ts between '21:45:00' and '22:45:00'

【问题讨论】:

  • “很遗憾,我目前没有查询” 也许您可以提供一个very minimal but working example depicting your issue。事实上,可能是最好的做法。
  • 详细信息为 (select to_char(complete_date, 'yyyy-mm-dd hh24:mi:ss') complete_date, to_char(complete_date, 'hh24:mi:ss') as ts from table where complete_date在 trunc(sysdate)-30 和 trunc(sysdate) 之间) select * from details where ts between '21:45:00' 和 '22:45:00'

标签: oracle filter timestamp intervals between


【解决方案1】:

我可以使用以下方法按时间戳进行过滤:

回合(提取(从 to_timestamp 开始的小时(完成日期,'yyyy-mm-dd hh24:mi:ss'))+(提取(从 to_timestamp 开始的分钟(完成日期,'yyyy-mm-dd hh24:mi:ss') )/60),2) count_ts

然后过滤 21.75 和 22.75 之间的 count_ts。这将使我无论在哪一天都能获得这些时间之间的任何数据。

问题解决了。

【讨论】:

  • 您应该接受您的回答,以便我们知道它已解决。
猜你喜欢
  • 2015-08-02
  • 1970-01-01
  • 1970-01-01
  • 2019-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多