[英]How to write a query to fetch data from exactly 25 mins back to 15 mins back? Oracle sql
I have a query like below; 我有一个类似下面的查询;
SELECT fielda,fieldb,fieldc
from mytable
where timefield between to_date((to_char(sysdate-1/24, 'DD-MON-YYYY HH24') || ':00:00'), 'DD-MON-YYYY HH24:MI:SS')
and to_date((to_char(sysdate-1/24, 'DD-MON-YYYY HH24') || ':59:59'), 'DD-MON-YYYY HH24:MI:SS');
This query takes value from the 0
th and 59
th minute of hour before previous hour. 该查询从前一小时的第
0
分钟到第59
分钟0
。 What I want is, I want to run a query, which runs on 10th minute. 我想要的是,我想运行一个查询,该查询在第10分钟运行。 The query should fetch rows from my table, where time is between 25 minures and 15 minutes related to the current.
该查询应从我的表中获取行,其中的时间与当前表之间的时间在25分钟到15分钟之间。 For example, I run the query in 09:10:00 and some seconds.
例如,我在09:10:00和几秒钟内运行查询。 It should fetch rows where timefield is between 08:50 and 08:59:00 (i want to include data in 8:50 and 8:59).
它应该获取时间字段在08:50和08:59:00之间的行(我想在8:50和8:59中包含数据)。 How can I do this?
我怎样才能做到这一点?
You'd truncate SYSDATE
to the minute and subtract the desired interval. 您将
SYSDATE
截断为分钟,然后减去所需的时间间隔。 Use >=
and <
in order to deal with seconds and fractions thereof properly. 使用
>=
和<
为了正确处理秒及其分数。
select fielda, fieldb, fieldc
from mytable
where timefield >= trunc(sysdate, 'minute') - interval '25' minute
and timefield < trunc(sysdate, 'minute') - interval '20' minute;
SELECT *
FROM mytable
WHERE timefield >= sysdate - (25/1440)
AND timefield <= sysdate - (10/1440)
24*60 = 1440
24 * 60 = 1440
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.