आधुनिक SQL के साथ , यह आसानी से विंडो फ़ंक्शन का उपयोग करके किया जा सकता है :
select invoice_number + 1 as gap_start,
next_nr - 1 as gap_end
from (
select invoice_number,
lead(invoice_number) over (order by invoice_number) as next_nr
from invoices
) nr
where invoice_number + 1 <> next_nr;
SQLFiddle:http://sqlfiddle.com/#!15/1e807/1