I have this SQL work fine except 1 point (at third value I need take previous time), this is the table (times) schema, output, and SQL:
id number time
-----------------------------------
1 9 00:00:10.000000
2 10 00:00:15.000000
3 9 00:00:22.000000
4 10 00:00:35.000000
1 9 00:00:55.000000
SELECT t.number, COUNT(1) laps,
GROUP_CONCAT(SEC_TO_TIME(time) ORDER BY t.id) times
FROM (
SELECT t1.id, t1.number,
TIME_TO_SEC(t1.time) - COALESCE(SUM(TIME_TO_SEC(t2.time)), 0) time
FROM times t1
LEFT JOIN times t2 ON t1.number = t2.number AND t2.id < t1.id
GROUP BY t1.id, t1.number, t1.time
) t
GROUP BY number
Result this output:
number laps times
-----------------------------------
9 3 00:00:10,00:00:12,00:00:23
10 2 00:00:15,00:00:20
I need this REsult expected:
number laps times
-----------------------------------
9 3 00:00:10,00:00:12,00:00:33
10 2 00:00:15,00:00:20
Where third time - previos calculated time, in this case (00:00:10,00:00:12,00:00:23 - 00:00:12) I Tried but SUM all times previous.