I want to get the difference between 2 days, where datetime 1 is now() , and datetime 2 is the previous log of a specific user.
I'm looking for something like this
TIMESTAMPDIFF(NOW(), Previous_Log_of_User)
So, if, for example, I have 2 users, and I have a teller_log table
name timestamp action duration
user1 2015-09-09 15:00:40 login 00:00:00
user1 2015-09-09 15:00:45 increment 00:00:05
user1 2015-09-09 15:00:52 increment 00:00:07
user2 2015-09-09 15:00:52 login 00:00:00
user1 2015-09-09 15: 00: 55` increment 00:00:03
user2 2015-09-09 15:00: 58` increment 00:00:06
user1 2015-09-09 15: 01: 00` logout 00:00:02
user2 2015-09-09 15: 01: 00` logout 00:00:02
As you can see in the above example, I have 2 users, and the starting point is if the user logs in , if the user action is an increment, I calculated the time between login and increment action, then if the user action increases again, we now calculate the duration between the previous increment and the increment now, etc. etc., until the user logs out, which will mark the end.
One of the problems that I am encountering here is that the table is incompatible, I cannot rely only on user_id to get the previous log of a specific user. There are times when the previous userid1 is the userid2.
Question:
Is there an easy way to do this besides using timedifference? Or any other approach I can take? I spend enough time here.
Edit:
I am using MySQL and VB.NET .
My database is like

Our task is the teller_log table, which logs any teller_info actions, and this teller_info table gets the username in the user_info table using the teller_id field as in user_info > and teller_info .
Then we can create a log with combined information from user_info and teller_info using the user_id field in the user_info table.
What I'm trying to achieve
- With this query, I can easily get the duration of all the logs. (For verification purposes) Does this mean that the query should not have
WHERE , although not sure? - I want to get the duration of the last log depending on the time, which means that if user1 increases, he will create a log, and in this log I will indicate the duration.