34,837
社区成员




create table tab(a int, b int)
insert tab select 1,1
union all select 2,3
union all select 22,33
union all select 222,333
union all select 2222,3333
union all select 22222,33333
select * from
(
select * from (select top 2 * from tab where a>=2 order by newid()) T
union all
select * from (select top 3 * from tab where a>=33 order by newid()) T
) T
order by newid()
drop table tab
/*
a b
----------- -----------
222 333
22 33
2222 3333
2222 3333
22222 33333
(5 row(s) affected)
*/
--这样?
select * from
(select top n1 * from tab where '条件a' order by newid()
union all
select top n2 * from tab where '条件b' order by newid())a
order by newid()