我需要在特定时间范围内查找行。
select *
from TableA
where startdate >= '12-01-2012 21:24:00'
and startdate <= '12-01-2012 21:25:33'
即:我需要查找时间戳精度为 SECONDS 的行。我如何实现这一目标?
仅供参考:该startdate
列的类型为TIMESTAMP
。
我需要在特定时间范围内查找行。
select *
from TableA
where startdate >= '12-01-2012 21:24:00'
and startdate <= '12-01-2012 21:25:33'
即:我需要查找时间戳精度为 SECONDS 的行。我如何实现这一目标?
仅供参考:该startdate
列的类型为TIMESTAMP
。
您需要使用to_timestamp()
将字符串转换为适当的timestamp
值:
to_timestamp('12-01-2012 21:24:00', 'dd-mm-yyyy hh24:mi:ss')
如果您的列是类型DATE
(也支持秒),则需要使用to_date()
to_date('12-01-2012 21:24:00', 'dd-mm-yyyy hh24:mi:ss')
要将其纳入where
条件,请使用以下命令:
select *
from TableA
where startdate >= to_timestamp('12-01-2012 21:24:00', 'dd-mm-yyyy hh24:mi:ss')
and startdate <= to_timestamp('12-01-2012 21:25:33', 'dd-mm-yyyy hh24:mi:ss')
您永远不需要to_timestamp()
在类型为 的列上使用timestamp
。
对于在时间戳中使用小数秒来访问此线程的每个人,请使用:
to_timestamp('2018-11-03 12:35:20.419000', 'YYYY-MM-DD HH24:MI:SS.FF')