select top 5 * from tb  where z_id=1 
union all
select top 5 * from tb  where z_id=2 
order by newid()

解决方案 »

  1.   


    select top 5 * into #tmp from tb  where z_id=1 order by newid()insert into #tmp select top 5 * from tb  where z_id=2 order by newid()select * from #tmp
      

  2.   

    select top 5 * from tb  where z_id=1 
    union 
    select top 5 * from tb  where z_id=2 
    order by newid()
      

  3.   

    select * from(
    select top 5 *,[newid]=newid() from tb  where z_id=1 order by [newid])a
    union all
    select * from(
    select top 5 *,[newid]=newid() from tb  where z_id=2 order by [newid])a
      

  4.   

    set rowcount 5
    select  * into #tmp from tb  where z_id=1 order by newid()insert into #tmp select * from tb  where z_id=2 order by newid()
    insert into #tmp select * from tb  where z_id=3 order by newid()
    ....set rowcount 0select * from #tmp order by newid()