请帮我解决这个问题。
我使用的是Oracle数据库,其中有一个表,其中每秒插入4-5条记录,因此我必须检查全天,如果至少15分钟没有发生标记。
发布于 2013-03-23 00:42:05
您可以使用lag检查这一点。
例如,假设您的字段名为数据类型为timestamp的ts:
select ts , prior_ts
from (select ts,
lag(ts) over (order by ts) prior_ts,
case
when ts - lag(ts) over (order by ts) > numtodsinterval(15, 'minute')
then 'x'
end gap_flag
from your_table
where ts between A and B -- limit checks to a range.
)
where gap_flag = 'x';因此,它会给出> 15分钟的间隔。
发布于 2013-03-23 01:19:47
使用EXTRACT来获取diff之间的一般示例。时间戳-很难在Dazzal的例子中添加任何东西:
SELECT (end_mm-start_mm) minutes_diff
FROM
( -- can extract hours and seconds the same way --
SELECT EXTRACT(MINUTE From start_ts) start_mm
, EXTRACT(MINUTE From end_ts ) end_mm
FROM
( -- initial data --
SELECT timestamp '2013-03-22 13:10:55' start_ts
, timestamp '2013-03-22 13:26:35' end_ts
FROM dual
))
/
Output: 16 minutes = 26 -10https://stackoverflow.com/questions/15575247
复制相似问题