select * from table where [id]<>id1 and [id]<>id2

解决方案 »

  1.   

    sorry ,刚才题目没有读清楚!
    select * from 表 where [id] not in (select [id] from one where [id]=条件1)
    and [id] not in (select [id] from one where [id] = 条件2)
    order by newid()
      

  2.   

    其中的 10000,你可以自己定义其他的:exec('select top ' + cast( rand() * 10000  as int) + ' * from a
          where id not in(id1) and id in(id2)' )
      

  3.   

    其中的 10000,你可以自己定义其他的:exec('select top ' + cast( rand() * 10000  as int) + ' * from a
          where id not in(id1) and id in(id2)' )
      

  4.   

    上面改一下:declare @i int
    set @i=rand()*10000
    exec('select top ' + @i + ' * from a
          where id not in(id1) and id in(id2)' )
      

  5.   

    select top N id     --N为数字
    from 表
    where id not in(集合id1)
          and id in (集合id2)
    order by newid()
      

  6.   

    楼上所有SQL的都不满足第二个条件,而是满足在id2(id2也为一个集合)中包含取出的id集合。
      

  7.   

    :( 我太马虎了,抱歉,又有个条件没有看清楚!确实要向各位老大学习才行!
    select top n * from 表 where [id] not in (select [id] from one where 条件1)
    or [id] in (select [id] from one where 条件2)
    order by newid()
      

  8.   

    Please try:select * from 表 
    where not exists(select id1 from 表 a where 表.id=a.id1 ) 
    and exists(select id2 from 表 b where b.id2=表.id)
    order by newid()
      

  9.   

    select distinct floor(round(hshsj,1)*10) as id into #pen from spkfk where floor(round(hshsj,1)*10)<>0
    select * from #pen a,table b where a.id=b.id and id not in (集合1) and id in (集合2)