日期:2014-05-18 浏览次数:20538 次
select top 5 * from Test where len(answer)=1 order by newid() select top 10 * from Test where len(answer)>1 order by newid()
------解决方案--------------------
select top 100 percent * from (select top 5 * from tb where type = '单选题' order by newid()) t union all select top 100 percent * from (select top 10 * from tb where type = '多选题' order by newid()) t
------解决方案--------------------
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()) T union all select * from (select top 10 * from @tb where type='多选题' order by newid()) T2 order by type, id /* ID type question resulta resultb resultc resultd answer ----------- ------ -------- ------- ------- ------- ------- ------ 1 单选题 问题1 选项A 选项B 选项C 选项D A 4 单选题 问题1 选项A 选项B 选项C 选项D C 15 单选题 问题1 选项A 选项B 选项C 选项D D 17 单选题 问题1 选项A 选项B 选项C 选项D B 18 单选题 问题1 选项A 选项B 选项C 选项D B 3 多选题 问题1 选项A 选项B 选项C 选项D AB 5 多选题 问题1 选项A 选项B 选项C 选项D AD 6 多选题 问题1 选项A 选项B 选项C 选项D BC 7 多选题 问题1 选项A 选项B 选项C