MySQL time difference between rows matching criteria -


hello need query on mysql database.

i have table looks 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 list time difference between action=0 , action=3 each unique trackid between specified date.

select distinct timediff        (                 (select `date` hesk_history `action` = 0),                 (select `date` hesk_history `action` = 3 )        ) diff     hesk_history  `date` between '2013-08-12 00:00:00' , '2013-08-12 23:59:59' 

the solution should list each distinct trackid , timediff between action 0 , action 3 when these action exist each trackid.

trackid       diff 2013-06-12-91 -00:01:22 

try joining table on this:

select      t1.trackid,     t2.date - t1.date     table t1     join table t2 on t2.trackid = t1.trackid , t1.action = 0 , t2.action = 3 t1.date between '2013-08-12 00:00:00' , '2013-08-12 23:59:59' 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -