有三张表
学生信息表:s(sno,sname,ssex,sdep,sclass)
课程信息表:c(cno,cname,teacher)
成绩表 :sc(sno,cno,grade)
怎样查询每门课分数最高的学生
查询结果中需显示三个字段 :学生姓名(sname),课程名(cname),成绩(grade)
求解呀 不知道有没好的看法呀
------解决方案--------------------
- SQL code
select s.sname , c.cname , t.gradefrom s , c , sc twhere s.sno = t.sno and t.cno = c.cno and t.grade = (select max(grade) from sc where cno = t.sno)select s.sname , c.cname , t.gradefrom s , c , sc twhere s.sno = t.sno and t.cno = c.cno and not exists (select 1 from sc where cno = t.sno and grade > t.grade)
------解决方案--------------------
- SQL code
select a.sname , b.cname , c.gradefrom s a , c b, sc cwhere a.sno = c.sno and b.cno = c.cno and not exists (select 1 from sc c where cno = c.sno and grade > c.grade)