select 起始印刷号,e.voucherno 终止印刷号,终止印刷号-起始印刷号+1 数量, e.status 状态 from (
select min(起始印刷号) 起始印刷号,终止印刷号 from (
select a.voucherno 起始印刷号,
isnull((select min(voucherno) - 1 from
t_voucher b
where b.voucherno >a.voucherno and a.status <> b.status),
(select max(voucherno) from t_voucher)) 终止印刷号
from t_voucher a) c
group by 终止印刷号) d,t_voucher e
where d.终止印刷号 = e.voucherno
select min(voucherno),max(voucherno),count(*),status
from
(select status,voucherno,to_number(voucherno)-row_number() over(partition by status order by voucherno) rn from a)
group by status,rn
order by 1