Mysql查询以一个缺失的id

@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;
posted @ 2021-05-19 10:15  是谁扭曲了时空  阅读(409)  评论(0编辑  收藏  举报