1.
select a.姓名 from s a,(select count(学号)as 学号 from sc group by 学号 having count(学号)=3) b where a.学号=b.学号
2.
select 学号 from sc where 课程号 in (select 课程号 from sc where 学号='2')

解决方案 »

  1.   

    1.select 姓名 from s
    where si=(select si from sc where (select count(学号)from sc ground by 学号))=3
    2.slect si from sc where 课程号 in(select 课程号 from sc where 学号=2)
      

  2.   

    1:select 姓名,count(*) as sum  from s inner join sc on s.学号=sc.学号 group by s.姓名 having  sum =(select count(*) from  s)
    2:表达不清淅
      

  3.   

    1.select a.姓名 from s a,
    (select count(学号)as 学号 from sc group by 学号 having count(学号)=(select count(*) from c)) b 
    where a.学号=b.学号
    2,select distinct 学号 from sc where 课程号 in (select distinct 课程号 from sc where 学号='2')
      

  4.   

    --测试数据
    CREATE table s (学号  int not null unique,
                    姓名  char(10),
    年龄  int,
    性别  char(2)
    )
    insert into s select 1,'李强',23,'男'
    union select 2,'刘丽',25,'女'
    union select 5,'张友',22,'男'
    gocreate table sc (学号 int, 
    课程号 char(3),
    分数 float)
    insert into sc select 1,'k1',83.0
    union select 2,'k1',85.0
    union select 5,'k1',92.0
    union select 2,'k5',90.0
    union select 5,'k5',94.0
    union select 5,'k8',80.0
    gocreate table c (课程号 char(3) not null unique,
    课程名 char(10),
    教师 char(8)
    )
    insert into c select 'k1','c语言','王华'    
    union select 'k5','数据库原理','程军'    
    union select 'k8','编译原理','程军'  --测试
    select a.姓名 from s a
    where a.学号 in (select 学号 from sc group by 学号 having count(学号)=3)select 学号 from sc where 课程号 in (select 课程号 from sc where 学号='2')--测试结果
    1、
    姓名张友2、
    学号1
    2
    2
    5
    5
          
      

  5.   

    select sno from s where not exists 
    (select * from sc a where a.sno=2 and not exists 
    (select * from sc b where s.sno=a.sno and a.cno=b.cno))这个是第二题的答案。。原来只是想让用NOT EXISTS
      

  6.   

    --s 
    --sc
    --c
    CREATE table s (学号  int not null unique,
                    姓名  char(10),
    年龄  int,
    性别  char(2)
    )
    insert into s select 1,'李强',23,'男'
    union select 2,'刘丽',25,'女'
    union select 5,'张友',22,'男'
    gocreate table sc (学号 int, 
    课程号 char(3),
    分数 float)
    insert into sc select 1,'k1',83.0
    union select 2,'k1',85.0
    union select 5,'k1',92.0
    union select 2,'k5',90.0
    union select 5,'k5',94.0
    union select 5,'k8',80.0
    gocreate table c (课程号 char(3) not null unique,
    课程名 char(10),
    教师 char(8)
    )
    insert into c select 'k1','c语言','王华'    
    union select 'k5','数据库原理','程军'    
    union select 'k8','编译原理','程军'  --测试1select s.姓名
     from s
      where s.学号 in
       (
        select sc.学号
          from sc
        group by 学号
       having count(学号)=3    
          )
    go
    --测试2
    select s.学号,s.姓名
     from s
    where s.学号 in 
       (
         select a.学号
          from sc a
           where a.课程号 in (select b.课程号 from sc b where b.学号='2')
        )
    godrop table s
    drop table sc
    drop table c
      

  7.   

    第一题
    begin transation
        declare @coucour int
        select @coucour=count(课程号) from c
        select a.姓名 from s a,(select count(学号)as 学号 from sc group by 学号  
               having count(学号)=@coucour) b where a.学号=b.学号
    commit tran
    本人是初学者
    此句有何错的地方请各位大哥指出。