(Apologies for the title of this question - I wasn't overly sure how to explain it)
Not sure whether this can be done in SQL. Below is a (somewhat truncated) sample of an event log table.
EVENT ID DATE TIME
--------- ---------- -------- ----
ONE_THING 0006241800 20091109 1719
ONE_THING 0006944800 20091109 1720
ANOTHER 0007517110 20091109 1721
ANOTHER 0007214240 20091109 1721
ANOTHER 0006907900 20091109 1725
ANOTHER 0006501580 20091109 1727
ONE_THING 0006944800 20091109 1737
ANOTHER 0005749820 20091109 1737
ANOTHER 0006810500 20091109 1738
ANOTHER 0007481970 20091109 1738
ANOTHER 0006331740 20091109 1739
ANOTHER 0007253840 20091109 1739
ANOTHER 0006929280 20091109 1747
ANOTHER 0007297950 20091109 1749
ANOTHER 0005055560 20091109 1751
ANOTHER 0006092320 20091109 1751
ONE_THING 0001668720 20091109 1753
ONE_THING 0007218000 20091109 1754
I'm looking to find groups of instances of ANOTHER where no other event has occurred in the group and for time periods in excess of 2 minutes.
So, in the above dataset, the first group would be:
ANOTHER 0007517110 20091109 1721
ANOTHER 0007214240 20091109 1721
ANOTHER 0006907900 20091109 1725
ANOTHER 0006501580 20091109 1727
and the second would be:
ANOTHER 0005749820 20091109 1737
ANOTHER 0006810500 20091109 1738
ANOTHER 0007481970 20091109 1738
ANOTHER 0006331740 20091109 1739
ANOTHER 0007253840 20091109 1739
ANOTHER 0006929280 20091109 1747
ANOTHER 0007297950 20091109 1749
ANOTHER 0005055560 20091109 1751
ANOTHER 0006092320 20091109 1751
And ideally I'd like to get:
ANOTHER 0007517110 20091109 1721
ANOTHER 0006501580 20091109 1727
and:
ANOTHER 0005749820 20091109 1737
ANOTHER 0006092320 20091109 1751
Or even better still:
EVENT DATE TIME_START TIME_END
--------- -------- ---------- --------
ANOTHER 20091109 1721 1727
ANOTHER 20091109 1737 1751
I thought about comparing rows but maybe there's a better way? I'd appreciate any tips for this. The solution just needs to work - it doesn't need to be necessarily fancy or elegant.
PS> I'm using Oracle.