是这意思吗
select s.sno,s.sname,s.sage,sc.cno,c.cno from sc ,s,c where sno=0002 and sc.sno=s.sno and c.cno=sc.cno

解决方案 »

  1.   

    select S.Sno,S.Sname
    from
    S,
    (
    select SC.Sno
    from  SC,
    (select C.Cno,count(*) as [Count]  from SC ,C  where SC.Cno=C.Cno and Sc.Sno='0002') B
    where Sc.Cno=B.Cno and SC.Sno<>'0002'
    group by SC.Cno
    having count(*)>=B.[Count]
    ) C
    where S.Sno=C.Sno--用虛擬表
    select SC.Sno into #temp
    from  SC,
    (select C.Cno,count(*) as [Count]  from SC ,C  where SC.Cno=C.Cno and Sc.Sno='0002') B
    where Sc.Cno=B.Cno and SC.Sno<>'0002'
    group by SC.Cno
    having count(*)>=B.[Count]select S.Sno,S.Sname
    from S,#temp A
    where S.Sno=A.Sno
      

  2.   

    select DISTINCT S.Sno,S.Sname from S,SC where S.Sno=SC.Sno and SC.Cno IN(select Cno from SC where Sno='0002')
    这是书上给的答案,但我觉得不对,在关键词IN,后来我一直想不出用什么,用>=all也不对,用=all也不对,所以想请教大家!
      

  3.   

    select s.sname,s.sage,c.cno sc.sno ,count(sc.cno) as ccno group by sno where (cno=002 or  cno=003) and (sc.sno=s.sno and c.cno=sc.cno)
      

  4.   

    以上错了。
    这个select s.sname,s.sage,c.cno sc.sno ,count(sc.cno) as ccno from s,sc,c group by sno where (cno=002 or  cno=003) and (sc.sno=s.sno and c.cno=sc.cno)
      

  5.   

    查询出至少选修了学号为0002所选修课程号的学号和姓名?
    这题目中都没有cno=002 or  cno=003,怎么写?
      

  6.   

    关键是这个
    select sno ,count(cno) as ccno from s group by sno where (cno=002 or  cno=003) 
    这样你就明白了吧
      

  7.   

    如果只查0002的那么再加上
    select sno ,count(cno) as ccno from s group by sno where (cno=002 or  cno=003) and sno=0002
    好了
      

  8.   

    不明白,count(cno) as ccno from s ,在S中都没有CNO
    你还是看清题目,理解意思,再做吧
      

  9.   

    create table s(sno varchar(10),sname varchar(10),sage int)
    create table sc(sno varchar(10),cno varchar(50) )insert into s values('0001','a',20)
    insert into s values('0002','b',20)
    insert into s values('0003','c',20)
    insert into s values('0004','d',20)
    insert into s values('0005','e',20)
    insert into s values('0006','f',20)insert into sc values('0001','001')
    insert into sc values('0001','002')
    insert into sc values('0001','003')
    insert into sc values('0002','002')
    insert into sc values('0002','003')
    insert into sc values('0003','002')
    insert into sc values('0004','001')
    insert into sc values('0004','002')
    insert into sc values('0005','003')
    insert into sc values('0006','002')
    insert into sc values('0006','003')
    insert into sc values('0006','005')select sno,sname from s m where 
    (select count(*) from sc a where sno=m.sno  and exists(select 1 from sc where sno='0002' and cno=a.cno))=(select count(*) from sc where sno='0002')drop table s,sc
      

  10.   

    select sno ,count(cno) as ccno from sc group by sno where (cno=002 or  cno=003) and sno=0002
      

  11.   

    select distinct s# from sc a where 
    no exists
    (select * from sc b where a.s#='0002' 
    and 
    not exists
    (select * from sc c where a.s#=c.s# and c.c#=b.c#))
      

  12.   

    --1:
    select sno,sname from s m where not exists
    (select 1 from sc a where sno='0002' and not exists(select 1 from sc where sno=m.sno and cno=a.cno))
    --2:
    select sno,sname from s m where 
    (select count(*) from sc a where sno=m.sno  and exists(select 1 from sc where sno='0002' and cno=a.cno))=(select count(*) from sc where sno='0002')
      

  13.   

    我的:
    select s.sname,s.sno from s where s.sno in(select sc.sno from sc where sc.cno in(select c.Cno from c where c.Cno in(select sc.Cno from sc where sc.Sno in(select s.Sno from s where s.Sage='0002'))))测试了的
      

  14.   

    这道题是某SQL教程的一个题
    我认为书上的答案没有错。
    请看清楚书上是怎么问的
    至少选修了学号为0002所选修课程号的
    他的意思并不是需要取出 0002 所选修的所有的课程 的结果
    也就是说
    0002 -> 002(Cno)
    0002 -> 003(Cno)他们是两个或者的关系。
    只要选者了002 或者 003的课程的学生所以答案是没有错:
    select DISTINCT S.Sno,S.Sname from S,SC where S.Sno=SC.Sno and SC.Cno IN(select Cno from SC where Sno='0002')我刚才写的那个:
    select s.sname,s.sno from s where s.sno in(select sc.sno from sc where sc.cno in(select c.Cno from c where c.Cno in(select sc.Cno from sc where sc.Sno in(select s.Sno from s where s.Sage='0002'))))
    效率更低。但是我可以取出所有的字段。包括选修课的名称。而如果是全部选修0002所有的课程的
    那么请参考
    xiaomeixiang(Little Sheep) 
    他的是对的!