SELECt a.id+1 AS start, MIN(b.id) - 1 AS end FROM testtable AS a, testtable AS b WHERe a.id < b.id GROUP BY a.id HAVINg start < MIN(b.id)
希望此链接也对http://www.prediesel.com/mysql/sequence-gaps-in-
mysql/有帮助

SELECt a.id+1 AS start, MIN(b.id) - 1 AS end FROM testtable AS a, testtable AS b WHERe a.id < b.id GROUP BY a.id HAVINg start < MIN(b.id)
希望此链接也对http://www.prediesel.com/mysql/sequence-gaps-in-
mysql/有帮助