try:
declare @num int
select @num=count(*) from table
where nodeid = 3 and styleid = 4 and Difficulty='难'
set @num=cast(@num*rand()+1 as int)
insert into tb_object 字段1,字段2,...(除了id外的所有字段) from (select identity(int,1,1) as id from table where nodeid = 3 and styleid = 4 and Difficulty='难') as a
where case when @num<4 then id between @num and @num+3 else id between @num-3 and @num end --要提多少题就加多少
select top 3 * from yourTable where nodeid = 3 and styleid = 4 and Difficulty = 1 order by newid()
union all
select top 4 * from yourTable where nodeid = 3 and styleid = 4 and Difficulty = 2 order by newid()
union all
....
不知道我是否理解你的意思正确
先建一个试图:my_view //查出满足知识点和题形的记录集
create view my_view
as
select * from from yourTable where nodeid = 3 and styleid = 4
///////////////////
select top 3 * from my_view where difficulty=1 order by 字段(随机排序标志)
union
select top 4 * from my_view where difficulty=2 order by 字段(随机排序标志)
union
select top 6 * from my_view where difficulty=3 order by 字段(随机排序标志)
union
select top 4 * from my_view where difficulty=4 order by 字段(随机排序标志)
union
select top 3 * from my_view where difficulty=5 order by 字段(随机排序标志)
select top 3 * from yourTable where nodeid = 3 and styleid = 4 and Difficulty='难'
order by newid()
union all
select top 4 * from yourTable where nodeid = 3 and styleid = 4 and Difficulty='较难'
order by newid()
union all
select top 6 * from yourTable where nodeid = 3 and styleid = 4 and Difficulty='中'
order by newid()
union all
select top 4 * from yourTable where nodeid = 3 and styleid = 4 and Difficulty='较易'
order by newid()
union all
select top 3 * from yourTable where nodeid = 3 and styleid = 4 and Difficulty='易'
order by newid()