关于SQL语句实现intersect“交”、except“差”运算的问题

w_f 2006-11-17 08:55:22
intersect“交”运算
(select a from tableA )
intersect (select a from tableB)
intersect (select a from tableC)

服务器: 消息 156,级别 15,状态 1,行 2
在关键字 'intersect' 附近有语法错误。
服务器: 消息 156,级别 15,状态 1,行 3
在关键字 'intersect' 附近有语法错误。

except“差”运算
(select a from tableA )
except (select a from tableB)
except (select a from tableC)

服务器: 消息 156,级别 15,状态 1,行 2
在关键字 'except' 附近有语法错误。
服务器: 消息 156,级别 15,状态 1,行 3
在关键字 'except' 附近有语法错误。

为什么?
请给出两个能够执行的例子。谢谢!
...全文
271 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
w_f 2006-11-18
  • 打赏
  • 举报
回复
谢谢各位的指教!
Well 2006-11-17
  • 打赏
  • 举报
回复
这两 个语句的用法是在2005才有的,intersect 取两个记录集的交集
except此取得的差集也就是左集-右集

zjcxc 元老 2006-11-17
  • 打赏
  • 举报
回复
不能的原因:
1. 你用的版本不是sql 2005, 这个是2005新增的
2. 版本是2005, 但数据库兼容级别在90以下, 所以无法使用90的语句.
zjcxc 元老 2006-11-17
  • 打赏
  • 举报
回复
-- 语句是没有问题的, 下面的示例我亲自测试过.

declare @a table(a int)
declare @b table(a int)
declare @c table(a int)

(select a from @a )
intersect (select a from @b)
intersect (select a from @c)

34,838

社区成员

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

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