首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎么查询每门课分数最高的学生

2012-09-14 
怎样查询每门课分数最高的学生?有三张表学生信息表:s(sno,sname,ssex,sdep,sclass)课程信息表:c(cno,cname

怎样查询每门课分数最高的学生?
有三张表
学生信息表: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) 

热点排行