求同一班级里面,相同年龄中英语成绩最高的学生
班级数量不定,年龄不定
一条sql能否求出来,谢谢各位
select a.age,max(a.分数) from A a group by a.age;
思路是: 根据年龄分组,求出每组中最大的分数
select b.* from tb_class b ,( SELECT age aage , max(fraction) amax from tb_class GROUP by age) a
where b.age = a.aage and b.fraction = a.amax;
思路:先查出每个年龄段的最高分
SELECT age aage , max(fraction) amax from tb_class GROUP by age
再根据最高分和年龄找到对应得人
select b.* from tb_class b ,( SELECT age aage , max(fraction) amax from tb_class GROUP by age) a
where b.age = a.aage and b.fraction = a.amax;
示例表格数据:
首先,查出相同班级的学生
select * from students a where (a.class) in (select class from students group by class having count(*) > 1)
其次 把 上面看成一个表table1,选出相同年龄的
select * from table1 a where (a.age) in (select class from table1 group by age having count(*) > 1)
把上面的看成table2,选出英语最好的
SELECT MAX(English) FROM table2
select max(id), max(name), max(point), age,class from students where point in (SELECT max(point) FROM students group by age, class) group by age, class order by class,age
实验通过此语句可以用