Skip to content

Instantly share code, notes, and snippets.

@zii
Last active October 14, 2015 04:04
Show Gist options
  • Save zii/6d2e4f09959443dad489 to your computer and use it in GitHub Desktop.
Save zii/6d2e4f09959443dad489 to your computer and use it in GitHub Desktop.
查询缺失的主键ID
# 查询缺失的主键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