Sum mysql results for each pair
<p>Table locations :</p>

<pre><code>+----+-----------+-----------+---------------------+
| Id | Old Value | New Value |        Date         |
+----+-----------+-----------+---------------------+
|  1 | Home      | Work      | 2016-11-01 09:00:00 |
|  2 | Work      | Home      | 2016-11-01 09:25:00 |
|  3 | Home      | Work      | 2016-11-01 09:44:59 |
|  4 | Work      | Home      | 2016-11-01 10:11:50 |
|  5 | Home      | Work      | 2016-11-01 10:25:30 |
|  6 | Work      | Home      | 2016-11-01 11:01:15 |
+----+-----------+-----------+---------------------+
</code></pre>

<p>My Query :</p>

<pre><code>    SELECT loc1.*,loc2.date AS loc2_date, SUM(CAST(TIMESTAMPDIFF(MICROSECOND,loc1.date,loc2.date)/1000000 AS DECIMAL(20))) AS time_diff
FROM locations AS loc1
        LEFT JOIN locations AS loc2 ON loc1.old_value=loc2.new_value AND loc2.id &gt; loc1.id
        WHERE old_value="Home"
</code></pre>

<p>My Query Result :</p>

<pre><code>Id: 1
Old Value: Home
New Value: Work
Date: 2016-11-01 09:00:00
Loc2_date: 2016-11-01 09:25:00
Time_fidd: 1500

Id: 1
Old Value: Home
New Value: Work
Date: 2016-11-01 09:00:00
Loc2_date: 2016-11-01 10:11:50
Time_diff: 4310

Id: 1
Old Value: Home
New Value: Work
Date: 2016-11-01 09:00:00
Loc2_date: 2016-11-01 11:01:15
Time_diff: 7275

Id: 3
Old Value: Home
New Value: Work
Date: 2016-11-01 09:44:59
Loc2_date: 2016-11-01 10:11:50
Time_diff: 1611

Id: 3
Old Value: Home
New Value: Work
Date: 2016-11-01 09:44:59
Loc2_date: 2016-11-01 11:01:15
Time_diff: 4576

Id: 5
Old Value: Home
New Value: Work
Date: 2016-11-01 10:25:30
Loc2_date: 2016-11-01 11:01:15
Time_diff: 2145
</code></pre>

<p>I wanna sum the date to see all the seconds I was at work. If I group by Id will show exactly what I need but when I sum the difference between <code>loc1.date</code> and <code>loc2.date</code> the query will skip group by and keep returning all the rows. Please help.</p>

<p>What I need from my query :</p>

<pre><code>Id: 1
Old Value: Home
New Value: Work
Date: 2016-11-01 09:00:00
Loc2_date: 2016-11-01 09:25:00
Time_fidd: 1500

Id: 3
Old Value: Home
New Value: Work
Date: 2016-11-01 09:44:59
Loc2_date: 2016-11-01 10:11:50
Time_diff: 1611

Id: 5
Old Value: Home
New Value: Work
Date: 2016-11-01 10:25:30
Loc2_date: 2016-11-01 11:01:15
Time_diff: 2145
</code></pre>