求一SQL语句

ycf330 2011-02-25 03:41:08
ID 学号 姓名 科目 成绩
01 01 A 语文 76
02 01 A 英语 33
03 01 A 数学 86
04 02 B 语文 66
05 02 B 英语 96
06 02 B 数学 67

查询出每个人最高的单科成绩~~谢谢
...全文
65 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
金色闪光 2011-02-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 gelyon 的回复:]
SQL code

select * from student a where not exists(select 1 from student b where a.学号=b.学号 and a.成绩<b.成绩)
[/Quote]


刚才试了一下,如果表中存在成绩为NULL值的情况下,那么空值将和最大值一起被显示出来,所以你应该这样

select * from student a where not exists(select 1 from student b where a.学号=b.学号 and a.成绩<b.成绩 and a.成绩 is not null and b.成绩 is not null
cffbest_521 2011-02-25
  • 打赏
  • 举报
回复
你试试看看这个可以吗?
SELECT sname AS 姓名, MAX(exam) AS 最高单科成绩
FROM StudyExam
GROUP BY sname
金色闪光 2011-02-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 gelyon 的回复:]
SQL code

select * from student a where not exists(select 1 from student b where a.学号=b.学号 and a.成绩<b.成绩)
[/Quote]


嗯 这是很棒的答案~ 学习了
gelyon 2011-02-25
  • 打赏
  • 举报
回复

select * from student a where not exists(select 1 from student b where a.学号=b.学号 and a.成绩<b.成绩)

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧