Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于获取特定日期范围/时段的时间范围内的记录的SQL查询_Sql_Oracle - Fatal编程技术网

用于获取特定日期范围/时段的时间范围内的记录的SQL查询

用于获取特定日期范围/时段的时间范围内的记录的SQL查询,sql,oracle,Sql,Oracle,正在查找SQL查询以获取特定日期段的时间范围内的表记录 比如说,, 如果我需要从表1中获取记录,如何编写查询 日期列>=2019-04-01和日期列

正在查找SQL查询以获取特定日期段的时间范围内的表记录

比如说,, 如果我需要从表1中获取记录,如何编写查询

日期列>=2019-04-01和日期列<2019-04-10

而且这些选定记录的时间应在12:00到13:00之间

注:TABLE1.DATE_列的数据类型为日期,该日期也包含时间部分


请帮助

使用以下条件

where DATE_COLUMN >= '2019-04-01 12:00:00' AND DATE_COLUMN < '2019-04-10 13:00:00'

使用条件如下

where DATE_COLUMN >= '2019-04-01 12:00:00' AND DATE_COLUMN < '2019-04-10 13:00:00'

我会尝试这样的方法:

select *
from your_Table
where date_column >= date '2019-04-01'
  and date_column <  date '2019-04-10'
  and to_number(to_char(date_column, 'hh24miss')) between 120000 and 130000;

我会尝试这样的方法:

select *
from your_Table
where date_column >= date '2019-04-01'
  and date_column <  date '2019-04-10'
  and to_number(to_char(date_column, 'hh24miss')) between 120000 and 130000;

您可以考虑使用Tunc函数,因为您需要小时间隔

with t(date_column) as
(
 select timestamp'2019-04-01 13:00:00' from dual union all
 select timestamp'2019-04-02 13:00:01' from dual union all
 select timestamp'2019-04-08 12:55:00' from dual    
)
select *  
  from t
  where ( to_char(date_column,'hh24') = '12'
     or ( to_char(date_column,'hh24') = '13' and trunc(date_column,'hh24') = date_column ) )
    and trunc(date_column) between date'2019-04-01' and date'2019-04-09';

DATE_COLUMN
-------------------
01.04.2019 13:00:00
08.04.2019 12:55:00

您可以考虑使用Tunc函数,因为您需要小时间隔

with t(date_column) as
(
 select timestamp'2019-04-01 13:00:00' from dual union all
 select timestamp'2019-04-02 13:00:01' from dual union all
 select timestamp'2019-04-08 12:55:00' from dual    
)
select *  
  from t
  where ( to_char(date_column,'hh24') = '12'
     or ( to_char(date_column,'hh24') = '13' and trunc(date_column,'hh24') = date_column ) )
    and trunc(date_column) between date'2019-04-01' and date'2019-04-09';

DATE_COLUMN
-------------------
01.04.2019 13:00:00
08.04.2019 12:55:00

你试过什么吗?你做过什么调查吗?谷歌搜索?你试过什么吗?你做过什么调查吗?谷歌搜索?我想他们想对每天的记录应用12:00到13:00之间的时间过滤器。我想他们想对每天的记录应用12:00到13:00之间的时间过滤器。可能有个小问题-因为你正在将时间转换为“hh24”,这将返回时间部分在12:00到13:59:59之间的任何内容。根据OP的精确程度,您可以只使用to_chardate_列,'hh24'=12。无论如何,这是正确的想法。真的,戴夫。谢谢你,修好了!亲爱的朋友,这在13:00:00之前还不起作用。你好,@Barbaros!有道理,正如OP在12点到13点之间所说的,13:00正好符合这一点。我对它进行了修改,使其能够处理长达几秒的时间;希望一切都会好起来。也谢谢你!谢谢@Littlefoot,这就是我要找的东西…:可能的小问题-由于您正在将时间转换为“hh24”,这将返回时间部分介于12:00和13:59:59之间的任何内容。根据OP的精确程度,您可以只使用to_chardate_列,'hh24'=12。无论如何,这是正确的想法。真的,戴夫。谢谢你,修好了!亲爱的朋友,这在13:00:00之前还不起作用。你好,@Barbaros!有道理,正如OP在12点到13点之间所说的,13:00正好符合这一点。我对它进行了修改,使其能够处理长达几秒的时间;希望一切都会好起来。也谢谢你!谢谢@Littlefoot,这就是我要找的东西…: