Last active
October 14, 2015 04:04
-
-
Save zii/6d2e4f09959443dad489 to your computer and use it in GitHub Desktop.
查询缺失的主键ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 查询缺失的主键ID | |
set @a := 0; | |
select t.r0, t.r1 from | |
( | |
select id, @a+1 as r0, id-1 as r1, if(id>@a+1, 0, 1) as 'series', @a:=id as 'a' from test | |
order by id | |
) t | |
where t.series=0 | |
order by t.id | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment