select  Student,Teacher,Course,Grade
from M4_Student 
where 
   Grade in  
   (  select max(Grade)
      from M4_Student 
      group by Course
   )

解决方案 »

  1.   

    select  Student,Teacher,Course,Grade
    from M4_Student 
    where  Grade in   
       (  select max(Grade)
          from M4_Student      
       )
    楼上的最后加了group by Course之后不能得到正确结果
      

  2.   

    为什么用 group by Course 之后不能得到正确结果????????
      

  3.   

    因為Grade in   <--好象是这里有错
       (  select Course,max(Grade)
          from M4_Student 
          group by Course
       )
    返回了兩個結果集合,有course和max(grade).不符合t_sql的語法規則.你只要把course去掉就好了.
      

  4.   

    上面的不行的,这样吧:
    select Student,Teacher,Course,Grade
    from M4_Student,(select Course,max(Grade) Grade from M4_Student group by Course) a
    where M4_Student.Course=a.Course and M4_Student.Grade=a.Grade
      

  5.   

    我是想求每门课程的最高成绩者
    问题解决了,应该这样写:
    select  Student,Teacher,Course,Grade
    from M4_Student a
    where  Grade in (select max(Grade)
          from M4_Student
          where course=a.course
          group by Course
       )
      

  6.   

    select  Student,Teacher,Course,Grade
    from M4_Student 
    where  Course+convert(varchar,Grade) in   <--好象是这里有错
       (  select Course+convert(varchar,max(Grade))
          from M4_Student 
          group by Course
       )
      

  7.   

    select  Student,Teacher,Course,Grade
    from M4_Student 
    where  Course+convert(varchar,Grade) in   <--好象是这里有错
       (  select Course+convert(varchar,max(Grade))
          from M4_Student 
          group by Course
       )