@i声明变量;id自增长,由于删除而id不连续,查询缺失id (id范围1至65535)
SELECT id-1 FROM
(
SELECT (@i:=@i+1) i, t1.id FROM test_table t1,(select @i:=0) it
WHERE cast(t1.id as DECIMAL) <= '65535'
AND cast(t1.id as DECIMAL) >= '1'
ORDER BY t1.id ASC
) t2
WHERE i != id
LIMIT 1;