Datum: 05.02.2013
, Kategorie:
MySQL
Mal wieder ein nützliches MySQL-Schnipsel.
SELECT a AS id, b AS next_id, (b - a) -1 AS missing_inbetween
FROM (
SELECT a1.id AS a , MIN(a2.id) AS b
FROM my_table AS a1
LEFT JOIN my_table AS a2 ON a2.id > a1.id
WHERE a1.id <= 100
GROUP BY a1.id
) AS tab
WHERE b > a + 1