Reputation: 390
I have this table on Oracle 11g:
CREATE TABLE USER.HISTORY_LOG
(
ID NUMBER,
DATE DATE,
COUNT_INSERTED_ROWS NUMBER,
EXEC_TIME VARCHAR2(50 BYTE)
)
Some data:
ID DATE COUNT_INSERTED_ROWS EXEC_TIME
6356 04/04/2016 09:36:03 1074 00h:00m:58s:769ms
6355 04/04/2016 09:33:00 1074 00h:00m:56s:221ms
6354 04/04/2016 09:30:11 1074 00h:01m:06s:719ms
6353 04/04/2016 09:27:13 1074 00h:01m:08s:977ms
6352 04/04/2016 09:24:13 1074 00h:01m:09s:361ms
6351 04/04/2016 09:21:12 1074 00h:01m:07s:685ms
6350 04/04/2016 09:18:11 1074 00h:01m:06s:657ms
6349 04/04/2016 09:15:01 1074 00h:00m:57s:074ms
This table is fed by a console app writen in c#, which runs every 3 minutes "forever"... But it can crash by some server's issue like unavailability.. and I must check if there was any time - and when - this happened. how can I do that using SQL? What I need is something like that:
Between date X and Y, it took more than 3 minutes to execute.
I want to solve using SQL.... is there any way I can do that? I confess that I'm out of ideas to build a query to do that.
Upvotes: 0
Views: 70
Reputation: 22949
You can try with something like this:
select *
from (
select lag(date_)over ( order by date_) as date_before_ko,
date_ as date_after_ko,
floor((date_ - lag(date_) over ( order by date_))*24*60) as minutes_passed
from HISTORY_LOG
)
where minutes_passed > 4
This computes, for each row, the preceeding record and checks if the difference in minutes between the two dates is more than 4.
Upvotes: 2