有表Test,假如有如下记录: 
ID   type    question resulta resultb  resultc  resultd   answer 
1     单选题    问题1     选项A   选项B     选项C    选项D      A 
2     单选题    问题1     选项A   选项B     选项C    选项D      B 
3     多选题    问题1     选项A   选项B     选项C    选项D      AB 
4     单选题    问题1     选项A   选项B     选项C    选项D      C 
5     多选题    问题1     选项A   选项B     选项C    选项D      AD 
6     多选题    问题1     选项A   选项B     选项C    选项D      BC 
7     多选题    问题1     选项A   选项B     选项C    选项D      AD 
8     多选题    问题1     选项A   选项B     选项C    选项D      CD 
9     多选题    问题1     选项A   选项B     选项C    选项D      BC 
10    多选题    问题1     选项A   选项B     选项C    选项D      BCD 
11    多选题    问题1     选项A   选项B     选项C    选项D      AB 
12    多选题    问题1     选项A   选项B     选项C    选项D      AD 
13    多选题    问题1     选项A   选项B     选项C    选项D      AC 
14    多选题    问题1     选项A   选项B     选项C    选项D      ABCD 
15    单选题    问题1     选项A   选项B     选项C    选项D      D 
16    单选题    问题1     选项A   选项B     选项C    选项D      B 
注:ID为题目的ID,type为题的类型,qusetion为问题,resulta,b,c,d为题的四个选项,answer为问题的标准答案 
现要求一条sql语句随机取出5道单选题记录和10道多选题记录(是随机取出,而且题目不能重复).小弟不会,特意来这请教各位大虾帮帮忙.解决立马结贴,在线等.分数不够可再加..谢谢大虾们帮忙..

解决方案 »

  1.   

    select top 5* from test where type='danxuan' order by newid()
    union
    select top 10* from test where type='duoxuan'order by newid()
      

  2.   

    select top 5 * from test where type ='单选题' order by newid()select top 10 * from testwhere type ='多选题' order by newid()
      

  3.   


    declare @tb table (ID int,type varchar(6),question varchar(5),resulta varchar(5),resultb varchar(5),resultc varchar(5),resultd varchar(5),answer varchar(4))
    insert into @tb
    select 1,'单选题','问题1','选项A','选项B','选项C','选项D','A' union all
    select 2,'单选题','问题1','选项A','选项B','选项C','选项D','B' union all
    select 3,'多选题','问题1','选项A','选项B','选项C','选项D','AB' union all
    select 4,'单选题','问题1','选项A','选项B','选项C','选项D','C' union all
    select 5,'多选题','问题1','选项A','选项B','选项C','选项D','AD' union all
    select 6,'多选题','问题1','选项A','选项B','选项C','选项D','BC' union all
    select 7,'多选题','问题1','选项A','选项B','选项C','选项D','AD' union all
    select 8,'多选题','问题1','选项A','选项B','选项C','选项D','CD' union all
    select 9,'多选题','问题1','选项A','选项B','选项C','选项D','BC' union all
    select 10,'多选题','问题1','选项A','选项B','选项C','选项D','BCD' union all
    select 11,'多选题','问题1','选项A','选项B','选项C','选项D','AB' union all
    select 12,'多选题','问题1','选项A','选项B','选项C','选项D','AD' union all
    select 13,'多选题','问题1','选项A','选项B','选项C','选项D','AC' union all
    select 14,'多选题','问题1','选项A','选项B','选项C','选项D','ABCD' union all
    select 15,'单选题','问题1','选项A','选项B','选项C','选项D','D' union all
    select 16,'单选题','问题1','选项A','选项B','选项C','选项D','B' union all
    select 17,'单选题','问题1','选项A','选项B','选项C','选项D','B' union all
    select 18,'单选题','问题1','选项A','选项B','选项C','选项D','B'select * from (select top 5 * from @tb where type='单选题' order by newid()) Tb1
    union all 
    select * from (select top 10 * from @tb where type='多选题' order by newid()) Tb2
    order by type, id
      

  4.   


    declare @tb table (ID int,type varchar(6),question varchar(5),resulta varchar(5),resultb varchar(5),resultc varchar(5),resultd varchar(5),answer varchar(4))
    insert into @tb
    select 1,'单选题','问题1','选项A','选项B','选项C','选项D','A' union all
    select 2,'单选题','问题1','选项A','选项B','选项C','选项D','B' union all
    select 3,'多选题','问题1','选项A','选项B','选项C','选项D','AB' union all
    select 4,'单选题','问题1','选项A','选项B','选项C','选项D','C' union all
    select 5,'多选题','问题1','选项A','选项B','选项C','选项D','AD' union all
    select 6,'多选题','问题1','选项A','选项B','选项C','选项D','BC' union all
    select 7,'多选题','问题1','选项A','选项B','选项C','选项D','AD' union all
    select 8,'多选题','问题1','选项A','选项B','选项C','选项D','CD' union all
    select 9,'多选题','问题1','选项A','选项B','选项C','选项D','BC' union all
    select 10,'多选题','问题1','选项A','选项B','选项C','选项D','BCD' union all
    select 11,'多选题','问题1','选项A','选项B','选项C','选项D','AB' union all
    select 12,'多选题','问题1','选项A','选项B','选项C','选项D','AD' union all
    select 13,'多选题','问题1','选项A','选项B','选项C','选项D','AC' union all
    select 14,'多选题','问题1','选项A','选项B','选项C','选项D','ABCD' union all
    select 15,'单选题','问题1','选项A','选项B','选项C','选项D','D' union all
    select 16,'单选题','问题1','选项A','选项B','选项C','选项D','B' union all
    select 17,'单选题','问题1','选项A','选项B','选项C','选项D','B' union all
    select 18,'单选题','问题1','选项A','选项B','选项C','选项D','B'select * from (select top 5 *,newid() randid from @tb where type='单选题' order by newid()) Tb1
    union all 
    select * from (select top 10 *,newid() randid from @tb where type='多选题' order by newid()) Tb2
    order by type, id