I would prefer to get this done in MySQL.
Table:
tracker | user_id | timestamp | action
1 1 1234 1
2 2 1236 9
3 1 1237 2
I need to find all users who had the action of 1, and subtract the timestamp from their next action. Meaning, User 1’s 1234 timestamp will be subtracted from his 1237 timestamp.
The idea is to calculate how long the user spent at action 1 until they went somewhere else.
Getting the first timestamp is easy. One idea is to record the tracker value, and then do a subquery for where user_id pops up again with a tracker higher than the first. In the example: WHERE user_id = 1 AND tracker > 1
Is there a more optimal solution?
Probably this helps you. This will join to all future actions
you probably want to extend to add also a condition to get the next one only.
this is some ad-hoc query, and can’t precisely tell if will work or not
This is suppose to select only the next one for that user.