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()
其中的 10000,你可以自己定义其他的:exec('select top ' + cast( rand() * 10000 as int) + ' * from a where id not in(id1) and id in(id2)' )
其中的 10000,你可以自己定义其他的:exec('select top ' + cast( rand() * 10000 as int) + ' * from a where id not in(id1) and id in(id2)' )
上面改一下:declare @i int set @i=rand()*10000 exec('select top ' + @i + ' * from a where id not in(id1) and id in(id2)' )
select top N id --N为数字 from 表 where id not in(集合id1) and id in (集合id2) order by newid()
楼上所有SQL的都不满足第二个条件,而是满足在id2(id2也为一个集合)中包含取出的id集合。
:( 我太马虎了,抱歉,又有个条件没有看清楚!确实要向各位老大学习才行! 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()
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()
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)
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()
where id not in(id1) and id in(id2)' )
where id not in(id1) and id in(id2)' )
set @i=rand()*10000
exec('select top ' + @i + ' * from a
where id not in(id1) and id in(id2)' )
from 表
where id not in(集合id1)
and id in (集合id2)
order by newid()
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()
where not exists(select id1 from 表 a where 表.id=a.id1 )
and exists(select id2 from 表 b where b.id2=表.id)
order by newid()
select * from #pen a,table b where a.id=b.id and id not in (集合1) and id in (集合2)