我现在在做一个在线考试系统,要从题目表singleproblem(假设题目表里面有100个题目)随机取出50个题目,结构如下:
id number not null primary key,
title varchar2(500) not null,
answer varchar2(500) not null,
rightanswer varchar2(500) not null,
state number not null,//1代表简单 2代表中级 3代表高级
type number not null,//1代表选择题 2代表多选题 3代表判断题
testid number题目有3种类型(type),现在我要取N个选择题,M个多选题,K个判断题,然后 N+M+K=50,就是根据一定的概率在50个题目中随机取,怎么做啊?高手求救。(不仅要随机,还要按比例)
id number not null primary key,
title varchar2(500) not null,
answer varchar2(500) not null,
rightanswer varchar2(500) not null,
state number not null,//1代表简单 2代表中级 3代表高级
type number not null,//1代表选择题 2代表多选题 3代表判断题
testid number题目有3种类型(type),现在我要取N个选择题,M个多选题,K个判断题,然后 N+M+K=50,就是根据一定的概率在50个题目中随机取,怎么做啊?高手求救。(不仅要随机,还要按比例)
解决方案 »
- 水晶报表动态改变纸张时,总是出现以下错误“设置打印机发生错误,错误信息为:无效索引。 (异常来自 HRESULT:0x8002000B (DISP_E_BADINDEX))”
- 读取网址的地址。
- 关于BindingSoure和DataSource,希望高人帮忙下
- 调用存储过程
- 高手帮忙:如何在服务器获取客户端用户登录后保存在session中的用户信息!
- 异步通信的线程关闭问题
- Window Mobile 下 用C#如果如何获取获取本机的DNS设置
- 没有用过Visio,各位同仁能介绍一下吗?谢谢
- 关于文件的设计!
- 急救,这样的错误如何解决?
- BackgroundWorker问题
- 如何得到BoundFiled里的字段
比如说随机获取简单的题目五道:
select top 5 * from singleproblem where state=1 order by newid()
as aa
union all
select * FROM ( select top 20 *, NewID() as random from singleproblem where [type]='2' order by random )
as bb
union all
select * FROM ( select top 15 *, NewID() as random from singleproblem where [type]='3' order by random )
as cc
select * FROM (select top 15 *, NewID() as random from singleproblem where [type]='1' order by random)
as aa
@N int ,
@M int,
@K int
as
begin
if((@N+@M+@K)>50)
return
select top (@N+@M+@K)* from
(
select * from tble
where [type]=1
union all
select * from tble
where [type]=2
union all
select * from tble
where [type]=3
)
as T0
end
Go
@N int ,
@M int,
@K int
as
begin
if((@N+@M+@K)>50)
return
select top (@N+@M+@K)* from
(
select * from tble
where [type]=1
union all
select * from tble
where [type]=2
union all
select * from tble
where [type]=3
)
as T0
end
Go
可不可以帮我把语句写出来,不用存储过程???非常感谢
<p style = "color:#f00"> up++ </p>
看来你还是没理解,,我用oracle只是写了一个类型为1的查询,,你把三条sql语句union all一下不就可以了。。还有随机共取50条记录,,那这个随机数在代码控制