SQL中有集合除法吗?

发布于 2024-07-04 21:54:02 字数 63 浏览 9 评论 0原文

我完全知道集合除法可以通过一系列其他操作来完成,所以我的问题是:

SQL中有集合除法的命令吗?

I'm fully aware that set division can be accomplished through a series of other operations, so my question is:

Is there a command for set division in SQL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

聚集的泪 2024-07-11 21:54:02

http://vadimtropashko.files.wordpress.com/2007/02/ch3.pdf

从第 32 页开始:

关系除法不是基本运算符。 它可以用投影、笛卡尔积、集合差来表示。

所以不行。 :)

http://vadimtropashko.files.wordpress.com/2007/02/ch3.pdf

From Page 32:

Relational Division is not a fundamental operator. It can be expressed in terms of projection, Cartesian product, and set difference.

So, no. :)

离不开的别离 2024-07-11 21:54:02

这是使用关系代数语法的很好的解释

给定表 sailorsboatsreserves(来自 Ramakrishnan 和 Gehrke 的“数据库管理系统”的示例),您可以计算预订了所有船只的水手使用以下查询:

SELECT name FROM sailors
WHERE Sid NOT IN (
    -- A sailor is disqualified if by attaching a boat,
    -- we obtain a tuple <sailor, boat> that is not in reserves
    SELECT s.Sid
    FROM sailors s, boats b
    WHERE (s.Sid, b.Bid) NOT IN (
        SELECT Sid, Bid FROM reserves
    )
);

-- Alternatively:
SELECT name FROM sailors s
WHERE NOT EXISTS (
    -- Not reserved boats
    (SELECT bid FROM boats)
    EXCEPT
    (SELECT r.bid FROM reserves r
    WHERE r.sid = s.sid)
);

Here is a nice explanation using relational algebra syntax.

Given tables sailors, boats and reserves (examples from Ramakrishnan & Gehrke's "Database Management Systems") you can compute sailors who have reserved all boats with the following query:

SELECT name FROM sailors
WHERE Sid NOT IN (
    -- A sailor is disqualified if by attaching a boat,
    -- we obtain a tuple <sailor, boat> that is not in reserves
    SELECT s.Sid
    FROM sailors s, boats b
    WHERE (s.Sid, b.Bid) NOT IN (
        SELECT Sid, Bid FROM reserves
    )
);

-- Alternatively:
SELECT name FROM sailors s
WHERE NOT EXISTS (
    -- Not reserved boats
    (SELECT bid FROM boats)
    EXCEPT
    (SELECT r.bid FROM reserves r
    WHERE r.sid = s.sid)
);
耳根太软 2024-07-11 21:54:02

相关问题:标记的数据库设计

答案的相关部分是这篇文章

所以简而言之,不,SQL 中没有设置划分。

Related question: Database Design for Tagging

And relevant part of answer is this article

So in short, no, there is no set division in SQL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文