連続して欠番してても取得できて、データ量が多くても
そこそこ速いクエリになった気がする。
SELECT (T1.[FIELD] + 1) AS '開始欠番',
(MIN(T2.[FIELD]) - 1) AS '終了欠番',
(MIN(T2.[FIELD]) - 1) -
(T1.[FIELD] + 1) + 1 AS '欠番数'
FROM (SELECT [FIELD]
FROM [TABLE]
WHERE ([FIELD] + 1)
NOT IN (SELECT [FIELD]
FROM [TABLE]))
AS T1
INNER JOIN [TABLE] AS T2
ON T2.[FIELD] > T1.[FIELD]
GROUP BY T1.[FIELD]
HAVING (T1.[FIELD] + 1) < MIN(T2.[FIELD])