请教一道SQL查询语句

来源:百度知道 编辑:UC知道 时间:2024/06/23 14:19:45
写sql语句,一个学生表(id,score,subject),查询每个学生分数最高的科目名称
注意:分数最高的可能同时是几门课

下面的sql能满足你的要求,我试验过了.

select B.id,B.subject from
(select id,max(score) 最高分 from table_name group by id)A,
table_name B
where A.id=B.id and A.最高分=B.score;

---
以上,希望对你有所帮助。

select subject
from 学生
where score=(select max(score) from 学生)
大概是这样吧

SELECT A.id,A.score,A.subject
FROM 学生表 AS A, (SELECT id,MAX(score) FROM 学生表 GROUP BY id HAVING MAX(score)) AS B
WHERE A.id=B.id AND A.score=B.MAX(score)

select id,score,max(subject) from [table name] group by id,score

这样就可以
select id,subject,max(score) from [table name] group by id,subject