select top 6 * from exam order by score desc

解决方案 »

  1.   

    select *
    from exam 
    where student_id in (select top 6 student_id from exam where class_id = '1' order by score desc)
      

  2.   

    select *
    from exam 
    where student_id in 
    (select top 6 student_id from exam t1 where t1.class_id =exam.classid and exam.student_id=t1.student_id
    order by score desc)
      

  3.   

    试试:
    select s.class_id,s.student_id,s.score 
    from exam s join exam t on (s.class_id=t.class_id) 
    where s.score<=t.score
    group by s.class_id,s.student_id,s.score
    having count(*)<=6
    order by 1,3 desc
      

  4.   

    select *
    from exam 
    where student_id in 
    (select top 6 t1.student_id from exam t1 where t1.class_id =exam.classid and exam.student_id=t1.student_id
    order by score desc)
      

  5.   

    select * from exam a
    where student_id in
    (
    select top 6 student_id from exam where class_id=a.class_id
    order by score desc
    )
      

  6.   

    嗨!
    我多了一个条件:
    and exam.student_id=t1.student_id