select top 20 * from yourTable where nodeid = 3 and styleid = 4 order by newid()
解决方案 »
- 怎样在SQLserver2005里定时执行一些脚本
- 求个SQL,谢谢
- sql 查询使用 in() 类型转换疑问
- 连接 局域网内其他电脑上的SQL Server 报错
- 面试题(SQL)
- ***< 超难问题,希望 zjcxc(邹建)高手给答复 >*** 如何用视图显示给定的ID的类别 以及它的所有父辛类的名字和id ,并且把查询给定的ID的类
- 各位大哥帮帮忙给想想办法,关于SQLServer2000数据库数据量的传输和服务器硬件性能的监测报告
- 开发中大型网站是选用sql server2000还是mysql更为合适?
- asp.net连接SQL SERVER出现问题了
- sql中有帮助语句吗?
- 我的新发现,快来看看............
- 如何按日期进行查询
这个我当然知道写,但是如何抽取难题3道,较难题4道;中等题6道;较易题4道;易题3道。
假设用1-5分别代表从难到易的级别。如何去查?
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()
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 字段(随机排序标志)
union all
select top 4 * from yourTable where nodeid = 3 and styleid = 4 and Difficulty = 2 order by newid()
union all
....
不知道我是否理解你的意思正确
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 --要提多少题就加多少同理就可以把随机抽取的 较难;中;较易;易 的考题数据插入表tb_object
语法我没试,仅把思路提供,有问题再回帖吧
^_^