I'm trying to do the following thing: I have table with users activities in system, and I want to create a sequence of activities according to the time of each activity on each object and when the time between each activity is up to 10 seconds, and to give each sequence an unique ID.
for example to following table :
userID ObjectID Timestamp
======== ========== =====================
1 52 2016-05-01 19:10:01
1 52 2016-05-01 19:10:05
1 52 2016-05-01 19:10:07
1 52 2016-05-01 19:12:01
1 52 2016-05-01 19:12:04
2 54 2016-05-01 19:11:09
2 54 2016-05-01 19:11:19
======== ========== ===================== == ==
on this table expected output is:
userID ObjectID Timestamp seq seqID
======== ========== =====================
1 52 2016-05-01 19:10:01 1 1
1 52 2016-05-01 19:10:05 2 1
1 52 2016-05-01 19:10:07 3 1
1 52 2016-05-01 19:12:01 1 2
1 52 2016-05-01 19:12:04 2 2
2 54 2016-05-01 19:11:09 1 3
2 54 2016-05-01 19:11:19 2 3
======== ========== ===================== == ==
I tried do it using row_number() and dense_rank() functions but I didn't succeed to do it with the 10 second different condition.