白日梦想jun 2016-05-07 11:05 采纳率: 100%
浏览 1264

SQL 相关子查询问题 分组问题

1、查询每个系的最高成绩
select x.sno,sdept,grade from student x,sc 
where x.sno = sc.sno and 
                    grade =(select max(grade) from sc,student 
                                where sc.sno=student.sno and sdept=x.sdept)

select x.sno,sdept,grade from student x,sc 
where x.sno = sc.sno and 
                    grade in(select max(grade) from sc,student 
                           where sc.sno=student.sno and sdept=x.sdept group by sdept)
        //用了相关子查询,这两个结果都是对的,但这里第二个的group by sdept是不是多余了啊?所以不写也是对的。谢谢指导。另外还有其他写法吗?
  • 写回答

0条回答 默认 最新

    报告相同问题?