select t4.id
from (select @id := @id + 1 id from table1 t1, (select @id := 0) t2, (select 1 union select 2) t3
where @id < t1.t_id - 1) t4
left join table1 t5 on t5.t_id = t4.id
where t5.t_id is null
table1 为要查询的表
t_id 为要查询表table1的主键id
t2 设置变量
t3 可选 如果id自增且非连续 查出的t1的最大id肯定会大于变量的最大值
如果有t3 t3的条数*t1的条数 就是变量id的最大值
可以根据情况设置t3
参考他人的自增序列写的