比如
新增表Credits(SNO,SumCredit,NoPass),表示每学生已通过选修课程的合计学分数,以及不及格的课程数。
合计学分数和不及格课程数的条件不一样,怎么查询?
Create table Credits as
(
(SELECT SNO FROM SC) NATURAL JOIN
(SELECT SNO,SUM(CREDIT) SUMCREDIT FROM SC NATURAL JOIN COURSES WHERE SC.GRADE>59) natural join
(SELECT SNO, COUNT(CNO) NOPASS FROM SC NATURAL JOIN COURSES WHERE SC.GRADE<60)
);
我用这样的连接查询也不行,Oracle说
(SELECT SNO FROM SC) NATURAL JOIN
这一句的Natural的N这里缺失右括号
我就是不想用连接,想知道有没有别的方法
追答外连接应该是必须的,因为你查询到的学号,有些只在第一个子查询中出现,有些只在第二个子查询中出现。
select a.sno, b.sumcredit, c.nopass from
(SELECT SNO FROM SC) a,
(SELECT SNO,SUM(CREDIT) SUMCREDIT FROM SC NATURAL JOIN COURSES WHERE SC.GRADE>59) b,
(SELECT SNO, COUNT(CNO) NOPASS FROM SC NATURAL JOIN COURSES WHERE SC.GRADE<60) c
where a.sno = b.sno (+)
and a.sno = c.sno (+)
求详细点的语句