日期:2014-05-17 浏览次数:20790 次
--举个例子
declare @a table(i int)
insert into @a
select number from master..spt_values
where type='P' and number>0 and number<11
declare @b table(i int)
insert into @b
select number from master..spt_values
where type='P' and number>0 and number<101
--以下执行
select i from @b as b where b.i=( select top 1 i from @a order by NEWID() )
union all
select * from ( select top 3 i from @b order by NEWID() ) as x
select top 10 * from
(
select rs from table1
union all
select rs from table2
) a
order by newid()
Create table tb1 (rs1 varchar(1))
Create table tb2 (rs1 varchar(1))
------------
Select tt.*
From tb1 as t1
Cross Apply
(
Select top (3) *
From tb2
Where tb2.rs1 = t1.rs1
Order by NEWID()
)as tt