日期:2014-05-18  浏览次数:20585 次

请教如何从试题库库中随机抽取符合要求的题目
现有试题数据表
--题库表结构
SQL code

create table tk(
id int primary key,--题目id
tk_content varchar(250),--题目内容
tk_difficulty varchar(10),--题目难易度 A易,B中,C难
tk_know varchar(10),--题目掌握程度,A掌握,B熟悉,C了解
tk_chapter varchar(50),--题目章节
)
insert into tk select 1,'题目内容1','A','A','第一章'
union all select 2,'题目内容2','A','A','第1章'
union all select 3,'题目内容3','A','A','第1章'
union all select 4,'题目内容4','B','A','第1章'
union all select 5,'题目内容5','B','A','第1章'
union all select 6,'题目内容6','B','A','第1章'
union all select 7,'题目内容7','C','B','第1章'
union all select 8,'题目内容8','C','C','第1章'
union all select 9,'题目内容9','C','C','第1章'
union all select 10,'题目内容10','A','A','第1章'
union all select 11,'题目内容11','A','A','第2章'
union all select 12,'题目内容12','A','A','第2章'
union all select 13,'题目内容13','A','A','第2章'
union all select 14,'题目内容14','B','A','第2章'
union all select 15,'题目内容15','B','A','第2章'
union all select 16,'题目内容16','B','B','第2章'
union all select 17,'题目内容17','C','B','第2章'
union all select 18,'题目内容18','C','C','第2章'
union all select 19,'题目内容19','C','B','第2章'
union all select 20,'题目内容20','C','C','第2章'
union all select 21,'题目内容21','A','A','第3章'
union all select 22,'题目内容22','A','A','第3章'
union all select 23,'题目内容23','A','A','第3章'
union all select 24,'题目内容24','B','A','第3章'
union all select 25,'题目内容25','B','A','第3章'
union all select 26,'题目内容26','B','A','第3章'
union all select 27,'题目内容27','C','A','第3章'
union all select 28,'题目内容28','C','B','第3章'
union all select 29,'题目内容29','C','B','第3章'
union all select 30,'题目内容30','C','C','第3章'
GO


要求
(2)从题库中随机抽取10题组成一套试卷,上面的题库不止30题,会不断增加;
(1)要求每份试卷第一章占4题(40%),第二章3题(30%),第章3题(30%);
(3)掌握占70%,熟悉占20%,了解10%;
(4)难易度 A易占20%,B中占60%,C难占20%;
应该怎么实现?请各位大侠指点一下,不胜感激!

------解决方案--------------------
SQL code
select top 10 * from tb order by newid()

------解决方案--------------------
都是top 40 percent