现在有两张表,一张为学生信息表Student(Code,Name),另外一张表为考试信息表
Exam(Code,Subject,Score)
Code Name Code Subject Score
001 张三 001 语文 80
002 李四 002 语文 90
003 王五 001 数学 70
004 小明 002 数学 90
001 英语 60
002 英语 70
003 英语 80
004 英语 90
用sql 查出(包括字段Code,Name,Subject,Socre) 每一门课程的最高分
Exam(Code,Subject,Score)
Code Name Code Subject Score
001 张三 001 语文 80
002 李四 002 语文 90
003 王五 001 数学 70
004 小明 002 数学 90
001 英语 60
002 英语 70
003 英语 80
004 英语 90
用sql 查出(包括字段Code,Name,Subject,Socre) 每一门课程的最高分
select t.code,s.name,t.subject,t.score from Student s right join(select t.code,t.subject,t.score from Exam t where not exists(select 1 from Exam where subject=t.subject and score>t.score))t on t.code=s.code;