Hello I need help with a query on a MySQL database.
I have a table that looks like this:
ID TRACKID DATE Name Action
38 2013-08-12-36 2013-08-12 14:54:50 John Smith 0
37 2013-08-12-39 2013-08-12 14:54:28 John Smith 3
36 2013-08-12-39 2013-08-12 14:53:24 John Smith 4
35 2013-06-12-91 2013-08-12 14:30:01 John Smith 3
34 2013-06-12-91 2013-08-12 14:29:44 John Smith 4
31 2013-06-12-91 2013-08-12 14:28:39 John Smith 0
I want to list the time difference between ACTION=0 and ACTION=3 for each unique TRACKID between a specified date.
SELECT DISTINCT TIMEDIFF
(
(select `date` from hesk_history where `action` = 0),
(select `date` from hesk_history where `action` = 3 )
) AS DIFF
FROM hesk_history
WHERE `date` BETWEEN '2013-08-12 00:00:00' AND '2013-08-12 23:59:59'
The solution should list each distinct TRACKID and the TIMEDIFF between Action 0 And Action 3 when these action exist for each TRACKID.
TRACKID DIFF
2013-06-12-91 -00:01:22