--输出每门功课成绩最好的学生数据,表名为 stu。mysql不是oracle

问题描述:

图片说明

select * from stu,(select course,MAX(mark) as maxscore from stu group by course) temp where stu.mark = temp.maxscore and stu.course= temp.course

SELECT id,name,MAX(mark),course FROM stu ORDER BY course

应该是group by ,sql语句为: SELECT id,name,MAX(mark),course FROM stu GROUP BY course

select s.* from stu s left join (select max(mark) m,course from stu GROUP BY course) c on s.mark=c.m and s.course=c.course where c.m is not null