17,377
社区成员
发帖
与我相关
我的任务
分享
select
a.日期,a.事务所,to_char(a.标章NO)||(case when a.标章NO=min(b.标章NO) then '' else '-'||to_char(min(b.标章NO)) end) as 标章NO
from
(select t.* from 表名 t where not exists(select 1 from 表名 where 日期=t.日期 and 事务所=t.事务所 and 标章NO=t.标章NO-1)) a,
(select t.* from 表名 t where not exists(select 1 from 表名 where 日期=t.日期 and 事务所=t.事务所 and 标章NO=t.标章NO+1)) b
where
a.日期=b.日期 and a.事务所=b.事务所 and a.标章NO<=b.标章NO
group by
a.日期,a.事务所,a.标章NO
select 日期,事务所,(to_number(标章NO.)-to_number(aa)) bb,min(标章NO.)||'-'||max(标章NO.)
from (select 日期,事务所,标章NO.,lag(标章NO.,1,9999) over (order by 日期,事务所,标章NO.) aa)
group by 日期,事务所,bb;