select top 20  * from yourTable where nodeid = 3 and styleid = 4 order by newid()

解决方案 »

  1.   

    To : zsforever(虎虎) 
    这个我当然知道写,但是如何抽取难题3道,较难题4道;中等题6道;较易题4道;易题3道。
    假设用1-5分别代表从难到易的级别。如何去查?
      

  2.   

    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()
      

  3.   

    先建一个试图: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 字段(随机排序标志)
      

  4.   

    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
    ....
    不知道我是否理解你的意思正确
      

  5.   

    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 --要提多少题就加多少同理就可以把随机抽取的 较难;中;较易;易 的考题数据插入表tb_object
    语法我没试,仅把思路提供,有问题再回帖吧
    ^_^