I have a user who has done a sequence of events. I want to capture the number of times they have done each event and in which order.
So for the following table user_events:
name eventname time
Ted a 12:01
Ted b 12:02
Ted b 12:03
Ted b 12:04
Ted c 12:05
Ted b 12:06
Ted b 12:07
Ted c 12:08
Ted b 12:09
Ted b 12:11
Ted b 12:12
I should get:
name eventname event_sequence_number time_started frequency
Ted a 1 12:01 1
Ted b 2 12:02 3
Ted c 3 12:05 1
Ted b 4 12:06 2
Ted c 5 12:08 1
Ted b 6 12:09 3
I've been attempting with rank(), dense_rank(), row_number() and lag() but can't put it all together. Any ideas?