列中有数据INT类型,1 4  5  7  8  9怎样自动查出2 3 6

解决方案 »

  1.   

    select id from
    (
    select 1 as id
    Union all select 2 Union all select 3
    Union all select 4 Union all select 5
    Union all select 6 Union all select 7
    Union all select 8 Union all select 9
    ) aa
    where id not in (select 你的列 from 你的表)
      

  2.   

    create table T
    ( id int)
    insert into T
    select 1 union
    select 4 union
    select 6 union
    select 8 union
    select 10 union
    select 11declare @max int select @max =max(id) from Tset rowcount @max
    select identity(int,1,1) as num into # from sysobjects,syscolumns
    set rowcount 0
    select num from # where num not in (select id from T)drop table #,T测试了.你试试
      

  3.   

    --测试数据
    create table T( id int)
    insert into T
    select 1 union
    select 4 union
    select 6 union
    select 8 union
    select 10 union
    select 11
    --查询语句
    select id-1 as 缺号 from t a where id>1 and not exists(select * from t where id=a.id-1)