首页 新闻 赞助 找找看

Sql 查询语句 ,求每个分组的最大值

0
悬赏园豆:20 [已关闭问题] 解决于 2018-04-04 09:33

一个学生表  Student (SId,学生名字SName)

一个成绩表  Score    (Id,课程name,学生SId,成绩 Score)

求查询每个学生的成绩最高的那门课程的信息的sql 语句 。 返回  (学生名字,课程名字 成绩)

ThierryHenry的主页 ThierryHenry | 初学一级 | 园豆:126
提问于:2018-04-02 16:54
< >
分享
其他回答(3)
0

Select SName,课程name,成绩Score

from Student,Score

where SId=Id and 成绩Score = (select Max(成绩Score) from Score where SId=Id)

Shendu.CC | 园豆:2138 (老鸟四级) | 2018-04-02 17:23
0

select ST.SName,SC.name,SC.Score from Student as ST left join(select SC2.id,SC2.name,SC2.SId,max(SC2.Score) as Score from (select * from Score order by Score) as SC2 group by SId) as SC on ST.SId=SC.SId;

如果有一个学生两个100分,这个sql只能显示其中一个。

让我发会呆 | 园豆:2929 (老鸟四级) | 2018-04-02 17:56
0

select   max(A.成绩),B.课程名字,B.学生名字   from  Student A,Score B

where A.SId=B.SId   group  by  A.课程名字,B.学生名字

陈chenchenhehehehe | 园豆:26 (初学一级) | 2018-04-03 08:58
0

select SName,name Score from Score a LEFT JOIN Student b on a.SId=b.SId
where Score= (select MAX(Score) from Score where SId=a.SId)

亲测:这个语句可以把同一个学生的两个最高分都可以查出来

华临天下 | 园豆:1501 (小虾三级) | 2018-04-03 09:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册