学习网考试学习资料

Gzu521.com

专业试题:计算机考试关系数据库标准语言--SQL(1)

专业指导   点击:次   发布时间:2006-8-8   【字体: 】   来源:Gzu521.com
贵 州 学 习 网

公务员考试专用训练软件《公务员考试百宝箱》1.0版

对于下述3个关系:
s (s#, sn, sa, sex)
c (C#, cn, teacher)
sc (s#, c#, grade) ZT+0|"Ey~(1W!*(q*m [ 本 资 料 来 源 于 贵 州 学 习 网 公务员考试专业指导 http://Www.gzU521.com ] ZT+0|"Ey~(1W!*(q*m

试用sql的查询语句表达下列查询:

(1) 检索liu老师所授课程的课程号和课程名。
  select c#, cn
  from c
  where teacher=’liu’

(2) 检索年龄大于23岁的男学生的学号和姓名。
 select s#, sn
from s
where sa>23 and sex=’男’

(3) 检索学号为s3学生所学课程的课程名和任课老师。
 方法一:
select cn, teacher
from c
where c# in
   (select c#
    from sc
    where s#=’s3’)
方法二:
  select cn, teacher
  from c, sc
  where c.c#=sc.c# and sc.s#=’s3’
方法三:
select cn, teacher
from c
where exists
   (select *
    from sc
    where sc.c#=c.c# and s#=’s3’)

公务员考试专用训练软件《公务员考试百宝箱》1.0版

公务员考试专用训练软件《公务员考试百宝箱》1.0版

(6) 检索至少选修两门课程的学生学号。
 方法一:
       select distinct s1.s#
       from sc as sc1, sc as sc2
       where sc1.s#=sc2.s# and sc1.c#!=sc2.c#
方法二:
   select s#
   from sc
   group by s#
having count(*)>=2
  
(7) 检索全部学生都选修的课程的课程号和课程名。
   方法一:
     select c#, cn
     from c
     where not exists
        (select *
         from s
         where not exists
              (select *
               from sc
               where sc.s#=s.s# and sc.c#=c.c#)
        )
    方法二:
     select c#, cn
     from c
     where not exists
        (select *
         from s
         where s# not in
              (select s#
               from sc
               where sc.c#=c.c#)
方法三:
  select c#, cn
  from c
  where c# in
    (select c#
     from sc
     group by c#

下一页
本文共3页: 第 1 [2] [3]

责任编辑:gzu521

公务员考试分类
考试信息
备考指南
面试指导
申论指导
公共基础指导
行政能力指导
专业指导
公开选拔领导考试
公安招警考试
分类推荐信息
  • 暂无相关信息
更多...
大类最新文章
更多...