读书人

查询数据库中某一列是否连续,该如何解

发布时间: 2012-01-29 21:39:32 作者: rapoo

查询数据库中某一列是否连续
数据库中有一列是NO,怎么样查询它的值是否连续

[解决办法]

SQL code
if exists(select 1 from tb a where no>(select min(no) from tb) and not exists(select 1 from tb where no=a.no-1))select '不连续'else'连续'
[解决办法]
SQL code
if exists(select 1 from tb group by no having max(no)-min(no)+1=count(*))print '存在' 

读书人网 >SQL Server

热点推荐