Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --有个表(tbig),数据量为kW级别,有一个字段(id)是整型,但是不连续,现在需要找出缺失的记录。
- WITH RECURSIVE t(n, present) as(
- SELECT 1, (SELECT exists(SELECT 1 FROM tbig WHERE tbig.id=1))
- UNION
- SELECT t.n+1, (SELECT exists(SELECT 1 FROM tbig WHERE tbig.id=t.n+1)) FROM t
- )
- SELECT n FROM t WHERE NOT present
- limit (SELECT MAX(tbig.id)-COUNT(*) FROM tbig)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement