id | time | type_event |
---|---|---|
1 | 2013-03-25 02:00:02 | 1 |
2 | 2013-03-25 02:30:22 | 1 |
3 | 2013-03-25 02:30:23 | 0 |
4 | 2013-03-25 02:50:22 | 0 |
5 | 2013-03-25 02:50:25 | 1 |
id | time_start | duration (сек.) | type_event |
---|---|---|---|
1 | 2013-03-25 02:00:02 | 1820 | 1 |
2 | 2013-03-25 02:30:23 | 1199 | 0 |
3 | 2013-03-25 02:50:25 | 0 | 1 |
SELECT @id:=0;
SELECT
@id:=@id+1 as id,
A.`time`,
IFNULL(UNIX_TIMESTAMP(A2.`time`)-UNIX_TIMESTAMP(A.`time`), 0) as dura,
A.type
FROM A
LEFT JOIN A A2
ON A.id + 1 = A2.id
WHERE
MOD(A.id, 2) = 1
AND A.`time` BETWEEN '2013-01-01' AND '2014-01-01';