Open this example in the interactive library
Source code
WITH ids(n) AS (VALUES(1),(2),(4)), gap AS (SELECT n,lead(n) OVER(ORDER BY n) AS next FROM ids) SELECT n+1 AS missing FROM gap WHERE next>n+1;
Sample output
[
{
"missing": 3
}
]
Open this example in the interactive library
WITH ids(n) AS (VALUES(1),(2),(4)), gap AS (SELECT n,lead(n) OVER(ORDER BY n) AS next FROM ids) SELECT n+1 AS missing FROM gap WHERE next>n+1;
[
{
"missing": 3
}
]