Reputation: 35
Given a series of numbers in table(c1), find the missing numbers. The numbers should be consecutive
c1
--
1
2
3
6
7
8
9
12
14
Expected output:
i
-
4
5
10
11
13
Upvotes: 1
Views: 38
Reputation: 1269773
Use generate_series()
:
select s.i
from (select generate_series(min(c1), max(c2), 1) as i
from t
) s left join
t
on s.i = t.c1
where t.c1 is null;
Upvotes: 3