更新时间:2022-09-14 15:08:45
原文地址:http://www.maomao365.com/?p=7335
create table test (keyId int,info varchar(60)) go insert into test(keyId,info)values (1,'maomao365.com'),(2,N'连续数判断'), (4,N'blog教程'),(5,'maomao'), (8,'test'),(9,'info') ; with tmp as (select ROW_NUMBER() over (order by keyId asc ) as keyIdNew, * from test ) select a.keyIdNew, a.keyId,a.info , case when ISNULL(a.keyId,0)-1 = b.keyId or b.keyId is null then '连续' else '不连续' end as '连续标志' from tmp a left join tmp b on a.keyIdNew = b.keyIdNew+1 ; go truncate table test drop table test