论坛有很多中类似的问题啊http://bbs.csdn.net/topics/390770715

解决方案 »

  1.   


    create table yw(ID int)insert into yw(ID)
     select 1 union all
     select 6 union all
     select 8 union all
     select 4
    select a.number 'ID'
    from
    (select number
     from master.dbo.spt_values
     where type='P' and number between 1 and (select max(ID) from yw)) a
    left join yw b on a.number=b.ID
    where b.ID is null/*
    ID
    -----------
    2
    3
    5
    7(4 row(s) affected)
    */
      

  2.   


    -- 凑个热门
    drop table seq 
    go
    select identity(int,1,1) rn into seq from sysobjects 
    go
    select top 1 rn from 
    (select ROW_NUMBER()over(order by name) rn from master..syscolumns) as t
    where t.rn not in (select rn from seq)
    order by 1 
      

  3.   


    怎么扯上了master表,type='P'是啥意思,这个不具有通用性,mysql里能用吗
    大概看明白意思,找出最大的值,然后在1和最大值间找不在表中的值
    mysql是怎么写?
      

  4.   

    纯粹复制粘贴的回复,哪来的by name
      

  5.   

    纯粹复制粘贴的回复,哪来的by name从哪里看到的是粘贴过来的,这段代码是我一个一个的打出来中,哪里来的 by name 自己看,擦亮眼镜看。