I have a table in which I have same the records but with different timestamps. E.g. - 1
2015-03-03 13:41:11.0 [createService]: [accountNumber = 123456]
2015-03-02 01:19:11.0 [createService]: [accountNumber = 123456]
2015-03-02 01:19:06.0 [createService]: [accountNumber = 123456]
E.g. - 2
2015-03-07 01:21:11.0 [createService]: [accountNumber = 567890]
2015-03-04 01:17:11.0 [createService]: [accountNumber = 567890]
I need to pull only the records that have more than 2 rows with a time difference of less than a minute on any single day. In the examples above i should only pull account 123456 since it has 2 records on the same day with a time difference of less than 60 seconds.
This is the query ive used to pull all records that have the createservice row more than once but need to filter the list furhter with the condition above -
SELECT acct_number
FROM CUSTOMER_LOG
WHERE LOG_EVENT LIKE '%createService%serviceName%'
AND LOG_EVENT_TMST > to_date('03/01/2015 00:00:00','MM/DD/YYYY HH24:MI:SS')
GROUP BY ACCT_NUMBER
having count(ACCT_NUMBER) > 1;
Could you please help me with a query that can accomplish this in the fastest time? Thank you in advance!
Get the previous timestamp using
lag()
. The rest is just basic querying: