I have an action table with a structure like this:
id prd_id act_dt grp ------------------------------------ 1 1 2000-01-01 00:00:00 2 1 2000-01-01 00:00:01 3 1 2000-01-01 00:00:02 4 2 2000-01-01 00:00:00 5 2 2000-01-01 00:00:01 6 2 2000-01-01 01:00:00 7 2 2000-01-01 01:00:01 8 3 2000-01-01 00:00:00 9 3 2000-01-01 00:00:01 10 3 2000-01-01 02:00:00
I want to break the data in this action table into a product ( prd_id
) and an activity date ( act_dt
) and update the group column ( grp
) with the value from the sequence for each of these groups.
Kicker, I need to group by the same timestamps, where the same means that "all records have a difference of exactly 1 second." In other words, within a group, the difference between any 2 records when sorted by date will be exactly 1 second, and the difference between the first and last records can be any amount of time if all the intermediate records are 1 second apart.
For example data, these groups will be:
id prd_id act_dt grp ------------------------------------ 1 1 2000-01-01 00:00:00 1 2 1 2000-01-01 00:00:01 1 3 1 2000-01-01 00:00:02 1 4 2 2000-01-01 00:00:00 2 5 2 2000-01-01 00:00:01 2 6 2 2000-01-01 01:00:00 3 7 2 2000-01-01 01:00:01 3 8 3 2000-01-01 00:00:00 4 9 3 2000-01-01 00:00:01 4 10 3 2000-01-01 02:00:00 5
What method would I use for this?
The size of the table is ~ 20 million rows, if this affects the method used to solve the problem.
source share