--查询学习C1、C5、C6三门课程的学生姓名
select SName
from S,SC
where S.SID=SC.SID and CID='C1'
intersect
select SName
from S,SC
where S.SID=SC.SID and CID='C5'
intersect
select SName
from S,SC
where S.SID=SC.SID and CID='C6'; 
这样写居然出错:在关键字 'intersect' 附近有语法错误。
郁闷啊!
我前几天按照书上例子输入了一个intersect的例子,也是这样的错误!到底什么原因??求助

解决方案 »

  1.   

    Intersect
    返回两个输入集合的交集,可以选择保留重复项。 语法
    Intersect(«Set1», «Set2»[, ALL])注释
    此函数返回 «Set1» 和 «Set2» 的交集。根据默认设置,在相交之前先删除两个集合中的重复项。 可选的 ALL 保留重复项。ALL 有几种工作方式。算法是:不重复的元素照常相交。对于 «Set1» 中的每个重复项,将其与 «Set2» 中的重复项相匹配,如果存在匹配的项,则在交集中保留匹配的重复项。示例
    示例Intersect({[1994], [1995], [1996]}, {[1995], [1996], [1997]})返回集合 {[1995], [1996]}。
      

  2.   

    你这个可以这样:
    select SName 
    from S,SC 
    where S.SID=SC.SID and (CID= 'C1' or CID= 'C5' or CID= 'C6')  
      

  3.   

    do熊,你的“union   all”也不对吧!我求的是交集,你这个是并集了!
      

  4.   

    --任选这三个中的一个SQL.
    select SName from S,SC where S.SID=SC.SID and (CID= 'C1' or CID= 'C5' or CID= 'C6')  --三个都选修的SQL.
    select SName from
    (
      select distinct SName from S,SC where S.SID=SC.SID and CID= 'C1'
      union all
      select distinct SName from S,SC where S.SID=SC.SID and CID= 'C5'
      union all
      select distinct SName from S,SC where S.SID=SC.SID and CID= 'C6'
    ) t
    group by SName having count(*) = 3
      

  5.   

    select   SName 
    from   S
    where exists (select 1 from SC where SID=S.SID and CID= 'C1')
    and exists (select 1 from SC where SID=S.SID and CID= 'C5')
    and exists (select 1 from SC where SID=S.SID and CID= 'C6')
      

  6.   


    select
    *
    from 
    S
    where not exists
    (select 1
    from (select CID='C1'union select CID='C5' union select CID='C6')T
    where not exists(select 1 from SC where CID=t.CID and SID=S.SID))
      

  7.   

    select sname
      from s a
     where 3 = ( select count(*) 
                  from sc b
                 where a.sID = b.Sid 
                   and b.cId in ('c1','c5','c6')
                ) 
      

  8.   

    intersect是用于Analysis Services的
      

  9.   

    问了我们数据库老师,他说sql2000这个环境不支持intersect
      

  10.   

    我也很晕,SQL2000不支持这样的Intersect,我这本教程是oracle 7 上是这样写的.