在多个日期间选择特定的时间戳间隔

问题描述:

我尝试过在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' 
+0

_“不幸的是,我现在没有查询”_也许你可以提供一个[描述你的问题的非常简单但实际的例子](http://*.com/help/mcve)。事实上,_that_可能是最好的做法。 – 2014-09-20 19:04:34

+0

详细信息as(选择to_char(complete_date,'yyyy-mm-dd hh24:mi:ss')complete_date,to_char(complete_date,'hh24:mi:ss')as ts from table where trunc(sysdate)-30之间的complete_date和trunc(sysdate))select * from details where'between '21:45:00'and '22:45:00' – user3186276 2014-09-20 19:31:45

我能够通过时间戳通过使用过滤:

回合(提取物(小时从TO_TIMESTAMP(complete_date, 'YYYY-MM-DD HH24:MI:SS'))+(提取物(分钟从to_timestamp(complete_date,'yyyy-mm-dd hh24:mi:ss'))/ 60),2)count_ts

然后筛选在21.75和22.75之间的count_ts。这将允许我在这些时间之间获取任何数据,而不管一天。

问题解决。