寻找一个SQL查询以获取特定日期时间段内某个时间范围内的TABLE记录。
例如,
如果我需要从表TABLE1
DATE_COLUMN >= 2019-04-01 AND DATE_COLUMN < 2019-04-10
以及这些选定记录的时间也应在12:00
至13:00
注意:TABLE1.DATE_COLUMN
的数据类型为DATE
,它也包含时间部分
请帮助
答案 0 :(得分:3)
我会尝试这样的事情:
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;
答案 1 :(得分:1)
由于小时间隔的需要,您可以考虑使用trunc()
功能
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
答案 2 :(得分:0)
使用条件如下
where DATE_COLUMN >= '2019-04-01 12:00:00' AND DATE_COLUMN < '2019-04-10 13:00:00'
答案 3 :(得分:0)
select * from TableName
where
convert(date,ColumnName) >= convert(date,'2019-04-01') and
convert(date,ColumnName) < convert(date,'2019-04-10') and
substring(CONVERT(VARCHAR, ColumnName, 108),0,6) between '16:54' and '17:56';