日期:2014-05-18 浏览次数:20634 次
--3. 列出既学过“1”号课程,又学过“2”号课程的所有学生姓名 select stuname from student s where exists( select 1 from elective e where exists( select 1 from elective where sNo=e.sNo and cNo=1 and e.cNo=2) and e.sNo=s.stuNo) /* stuname 李明 */
------解决方案--------------------
4 5没看懂,帮顶.
------解决方案--------------------
-- 3. 列出既学过“1”号课程,又学过“2”号课程的所有学生姓名???????
select stuName from student s where exists(select 1 from course where sNo=s.stuNo and cNo = 1) and exists(select 1 from course where sNo=s.stuNo and cNo = 2)
------解决方案--------------------
-- 3. 列出既学过“1”号课程,又学过“2”号课程的所有学生姓名 select m.stuname from student m where stuNo in ( select sno from ( select distinct sno from elective where cno = 1 union all select distinct sno from elective where cno = 1 ) t group by sno having count(1) = 2 ) /* stuname ------- 李明 (所影响的行数为 1 行) */ -- 4.列出“1”号课成绩比“2”号同学该门课成绩高的所有学生的学号 --你的sno为1,cno为2怎么多次? select m.stuno from student m, elective n1 , elective n2 where m.stuno = n1.sno and m.stuno = n2.sno and n1.cno = 1 and n2.cno = 2 and n1.elecgrade > n2.elecgrade /* stuno ----------- 1 1 (所影响的行数为 2 行) */ select distinct m.stuno from student m, elective n1 , elective n2 where m.stuno = n1.sno and m.stuno = n2.sno and n1.cno = 1 and n2.cno = 2 and n1.elecgrade > n2.elecgrade /* stuno ----------- 1 (所影响的行数为 1 行) */ --5.列出“1”号课成绩比“2”号课成绩高的所有学生的学号及其“1”号课和“2”号课的成绩 --你的sno为1,cno为2怎么多次?所以出现两个结果 select m.stuno , n1.elecgrade , n2.elecgrade from student m, elective n1 , elective n2 where m.stuno = n1.sno and m.stuno = n2.sno and n1.cno = 1 and n2.cno = 2 and n1.elecgrade > n2.elecgrade /* stuno elecgrade elecgrade ----------- ----------- ----------- 1 80 70 1 80 60 (所影响的行数为 2 行) */