码迷,mamicode.com
首页 > 数据库 > 详细

oracle/sql.

时间:2014-05-10 01:49:23      阅读:367      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   color   

3 table S(student), C(course), SC(StudentCourse):

s(sno,sname)

c(cno,cname,cteacher)

sc(sno, cno, scgrade)

Q:

  1. 找出没选过“liming”老师的所有学生姓名.
  2. 列出2门以上(含2门)不及格学生姓名及平均成绩.
  3. 既学过1号课程又学过2号课所有学生的姓名.

A:

  1,

1 select sname from s join sc on(s.sno = sc.sno) join c on(sc.cno = c.cno)
2 where cteacher <> liming

  2.1,

1 select sname from s where sno in
2 (
3 select sno from sc where scgrade < 60 group by sno having count(*) >= 2
4 )

  2.2,

bubuko.com,布布扣
1 select avg(scgrade) from sc join s on(sc.sno = s.sno)
2 where sname in
3 (
4     select sname from s where sno in
5     (
6         select sno from sc where scgrade < 60 group by sno having count(*) >= 2
7     )
8 ) group by sname
bubuko.com,布布扣

  3,

1 select sname from s join sc on(s.sno = sc.sno)
2 where sno in
3 (
4     select sno from sc where cno = 1 and sno in 
5     (select sno from sc where cno = 2)
6 )

 

 ref: oracle

oracle/sql.,布布扣,bubuko.com

oracle/sql.

标签:style   blog   class   code   java   color   

原文地址:http://www.cnblogs.com/listened/p/3708051.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!