create table t2(x int constraint pk_t2 primary key);
go

insert into t2(x) values(1),(2),(3),(5),(7),(8),(11),(12),(13);
go

--解决方法 1:
with cteA as(
select x ,(select min(x) from t2 as b where b.x>=a.x and not exists (select x from t2 as c where c.x=b.x+1)) as endNumber
from t2 as a)

select min(x) as StartNumber,endNumber from cteA
group by endNumber;
go

--解决方法 2:

with cteB as(
select x,x-rowNumber as diff from (select x,ROW_NUMBER() over(order by x) as rowNumber from t2) as a)

select min(x),max(x) from cteB
group by diff;
go

 

相关文章:

  • 2022-12-23
  • 2021-09-10
  • 2022-01-07
  • 2021-05-29
  • 2022-12-23
  • 2021-11-08
猜你喜欢
  • 2021-04-24
  • 2021-07-27
  • 2022-12-23
  • 2021-04-06
  • 2021-06-26
  • 2021-07-12
  • 2021-12-21
相关资源
相似解决方案