表1s(s#,sn,sd,sa) s#,sn,sd,sa分别是学号,姓名,单位,年龄  表2 c(c#,cn) c#,cn分别是课程编号,课程名称  表3 sc(s#,c#,g) s#,c#,g分别是学号,课程编号,学习成绩。如何建这三个表。 1使用sql嵌套查询选修课程名称为“税收基础”的学员学号和姓名。2使用sql嵌套查询不选修课程编号为‘c5’的学员姓名和单位。3使用sql嵌套查询选修全部课程的学员姓名和单位。

解决方案 »

  1.   

    create table s
    (
     s# number(3) primary key,
     sn char(10) ,
     sd char(10),
     sa number(2)
    );create table c
    (
     c# number(3) primary key,
     cn char(10) 
    );
    create table sc
    (
     s# number(3) references s,
     c# char(10)  references c,
     g  number(2);
     primary key(s#,c#)
    );(1):
     select s#,sn
     from s
     where s.s# in 
        ( 
          select sc.s#
          from sc 
          where  sc.c# in 
             (
               select c# 
               from c
               where cn="税收基础"
              )
          );
    (2)
     select sn,sd
     from s
     where s.s# in 
        ( 
          select sc.s#
          from sc 
          where  sc.c# != c5
          );
    (3)
    select sn,sd
    from s 
    where not exists  
    (
     select *
     from c
     where not exists( 
            select *
            from sc
            where s# =s.s# and c# = c.c#    
         )
    )