Create Table TableName ( ID int )insert into TableName (ID) Values (1) insert into TableName (ID) Values (2) insert into TableName (ID) Values (3) insert into TableName (ID) Values (4) insert into TableName (ID) Values (9) insert into TableName (ID) Values (10) insert into TableName (ID) Values (11) insert into TableName (ID) Values (19) insert into TableName (ID) Values (20) Select Top 1 ID-1 From TableName Where ID-1 Not In ( Select ID From TableName ) Order By ID Desc--得到缺失ID中最大的一个,结果是:18Select Top 1 ID+1 From TableNamer Where ID+1 not in (Select ID From TableName) Order By ID Asc--得到缺失ID中最小的一个,结果是:5