I have one table which has sequence number.
I want to find the missing sequence number which is minimum out of missing numbers.
For eg.,
Seq No: 1,2,3,5,7,9 ==> Expected result: 4
Seq No: 1,2,3,4,5,6,7,9,15 ==> Expected result: 8
You can try with row_number()
with cte as
(
select seq,seq-row_number() over(order by seq) as diff
from tablename
)
select * from cte where diff<>0 and diff in (select min(diff) from cte where diff<>0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With