--查询学习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的例子,也是这样的错误!到底什么原因??求助
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的例子,也是这样的错误!到底什么原因??求助
返回两个输入集合的交集,可以选择保留重复项。 语法
Intersect(«Set1», «Set2»[, ALL])注释
此函数返回 «Set1» 和 «Set2» 的交集。根据默认设置,在相交之前先删除两个集合中的重复项。 可选的 ALL 保留重复项。ALL 有几种工作方式。算法是:不重复的元素照常相交。对于 «Set1» 中的每个重复项,将其与 «Set2» 中的重复项相匹配,如果存在匹配的项,则在交集中保留匹配的重复项。示例
示例Intersect({[1994], [1995], [1996]}, {[1995], [1996], [1997]})返回集合 {[1995], [1996]}。
select SName
from S,SC
where S.SID=SC.SID and (CID= 'C1' or CID= 'C5' or CID= 'C6')
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
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')
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))
from s a
where 3 = ( select count(*)
from sc b
where a.sID = b.Sid
and b.cId in ('c1','c5','c6')
)