select Student,Teacher,Course,Grade
from M4_Student
where
Grade in
( select max(Grade)
from M4_Student
group by Course
)
from M4_Student
where
Grade in
( select max(Grade)
from M4_Student
group by Course
)
from M4_Student
where Grade in
( select max(Grade)
from M4_Student
)
楼上的最后加了group by Course之后不能得到正确结果
( select Course,max(Grade)
from M4_Student
group by Course
)
返回了兩個結果集合,有course和max(grade).不符合t_sql的語法規則.你只要把course去掉就好了.
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
问题解决了,应该这样写:
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
)
from M4_Student
where Course+convert(varchar,Grade) in <--好象是这里有错
( select Course+convert(varchar,max(Grade))
from M4_Student
group by Course
)
from M4_Student
where Course+convert(varchar,Grade) in <--好象是这里有错
( select Course+convert(varchar,max(Grade))
from M4_Student
group by Course
)