INTERSECT 在SQL SERVERS7.0中的用法???

adu 2001-02-10 11:32:00
schema:
Sailors(sid;integer, sname:string, rating:real, age:real)
primary key(sid)
Boats(bid:integer, bname;string, color:string)
primary key(bid)
Reserves(sid:integer, bid integer,date:datetime)
primary key(sid,bid,date)
foreign key(sid,bid)

Find the name of Sailor who have server both red boat and green boat

SELECT S.sname
FROM Sailors As S
WHERE S.sid In
((SELECT R.sid
FROM Reserves As R ,Boats As B
WHERE R.bid =B.bid and B.color='red')
INTERSECT
(SELECT R2.sid
FROM Reserves As R2 ,Boats As B2
WHERE R2.bid =B2.bid and B2.color='green')
)

在sql server7.0中运行,说INTERSECT语法错误。
各位大虾,这个query在sql server7.0怎么写。
另外,我运行这个query是可行的。
Find the name of Sailor who have server both red boat or green boat

SELECT S.sname
FROM Sailors As S
WHERE S.sid In
((SELECT R.sid
FROM Reserves As R ,Boats As B
WHERE R.bid =B.bid and B.color='red')
UNION
(SELECT R2.sid
FROM Reserves As R2 ,Boats As B2
WHERE R2.bid =B2.bid and B2.color='green')
)


...全文
97 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangzi 2001-02-10
  • 打赏
  • 举报
回复
你的INTERSECT用法是错的。
你可以这样写呀:
SELECT S.sname
FROM Sailors As S
WHERE (S.sid In
(SELECT R.sid
FROM Reserves As R ,Boats As B
WHERE R.bid =B.bid and B.color='red'))
and
(S.sid In
(SELECT R.sid
FROM Reserves As R ,Boats As B
WHERE R.bid =B.bid and B.color='green'))


我想这样就可以了。
adu 2001-02-10
  • 打赏
  • 举报
回复
谢谢你,的确是这样的。
我们可以交个朋友吗?
我的信箱是joininthegame@163.net

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧