SQL实现单字段 分段查询

 select min(qrCode) as minqr,max(qrCode) as maxqr from
 (select row_number() over ( partition by [CPLairageCode] order by qrcode) as id1 ,
                   row_number() over ( order by qrcode ) as id2 ,*
          from      [FZ_GuaJie]
           ) t
           where CPLairageCode = @CPLairageCode
 group by id2 - id1
 order by minqr
select min(qrCode) as minqr,max(qrCode) as maxqr from
	(select row_number() over ( partition by [CPLairageCode] order by qrcode) as id1 ,
                   row_number() over ( order by qrcode ) as id2 ,*
          from      [FZ_GuaJie]
           ) t
           where CPLairageCode = @CPLairageCode
	group by id2 - id1
    order by minqr

你可能感兴趣的:(SQL实现单字段 分段查询)