S
S
shakawkaw2015-09-22 00:22:10
MySQL
shakawkaw, 2015-09-22 00:22:10

How to select time-to-jump/gap extremes from MySQL?

Help me choose the boundary values ​​of the TIMESTAMP type in MySQL. There is a table with timestamps. Stamps come in batches with an interval of 1 second and random intervals between batches. Is there a way in pure sql to get the start and end value of each pack?
for example, values:
1442800001
1442800002
1442800003
1442800004
1442866661
1442866662
1442866663
get as:
+----------------+-----------------+
|..........t1.........|...........t2.........|
+----------------+-----------------+
| 1442800001 | 1442800004 |
| 1442866661 | 1442866663 |
+----------------+-----------------+

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2015-09-22
@shakawkaw

Perversion, of course:

SET @t = 0;
SET @p = 0;
SELECT MIN(`time`) AS `t1`, MAX(`time`) AS `t2` 
    FROM (
        SELECT `time`, @t AS `prev`, 
                @p := IF(@t+1 = `time`, @p, @p+1) AS `packet`, 
                @t := `time` 
        FROM `table` 
        ORDER BY `time`
    ) AS `t` 
    GROUP BY `packet` 
    ORDER BY `packet`;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question