嗨,我正尝试从oracle表中获取最后5分钟的数据。查询写在下面,因此无法正常工作。
select * from mytable where (time_to_sec(timediff(now(),mytable.time_stamp)) <= 300)
其显示此错误ORA-00904。
我尝试了另一个查询。
select * from mytable where TIME_STAMP > (sysdate - numtodsinterval(5,'minute'))
现在,您能否告诉我该查询提取了最近5分钟的数据,并且删除了表中超过12小时的数据。
我在oracle和mysql中都需要查询。我尝试过的mysql查询在这里。
delete from mytable where (time_to_sec(timediff(now(),time_stamp))/3600 >12);
在oracle中,从时间戳中减去1表示一天。并且您可以减去一小部分。所以,
current_timestamp - (5/(24*60))
给您5分钟前的约会。使用它我们可以查询:
select * from mytable where TIME_STAMP > current_timestamp - (5/(24*60)
哪个应该给您所需的结果。与使用特殊功能相比,我发现此方法更直接,更容易记住。
如果您要过滤过去12小时内的数据,则可以这样查询数据:
select * from mytable where TIME_STAMP <= current_timestamp - 0.5
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句