求一条sql,一对多,查询所有班级中分数最高的学生

学习 时间:2026-10-24 07:17:39 阅读:9322
求一条sql,一对多,查询所有班级中分数最高的学生表结构如下:分数表(scores)class_id(班级) stu_id(学生) score(分数)1班 学生1 1001班 学生2 501班 学生3 02班 学生4 903班 学生5 90现在的需求是查询出每个班级中分数最高的一位同学,求SQL.期望的结果是:class_id(班级) stu_id(学生) score(分数)1班 学生1 1002班 学生4 903班 学生5 90

最佳回答

贤惠的学姐

单纯的小刺猬

2026-10-24 07:17:39

select c。class_id as 班级 ,stu_id as 学生,f as 分数 from
( select class_id,max(score) as f from scores group by class_id) c
join scores on scores。class_id=c。class_id and scores。score = c。f

最新回答共有2条回答

  • 可靠的灯泡
    回复
    2026-10-24 07:17:39

    select c。class_id as 班级 ,stu_id as 学生,f as 分数 from ( select class_id,max(score) as f from scores group by class_id) c join scores on scores。class_id=c。class_id and scores。score = c。f

上一篇 这道题怎么算?请写出计算过程和为什么这么做,答案请写成带分数.

下一篇 家居装修中哪些地方需要安装地漏