关系代数语法

发布于 2024-10-07 07:59:14 字数 545 浏览 3 评论 0原文

今天我第一次遇到数据库关系代数问题,我似乎找不到答案。

我有 3 个表,Batch、Channel 和 Market。

Batch 通过外部键(channelID、marketID)连接到 Channel 和 Market。

这种查询的正确表示法是什么:

select * from batch, channel, market 
where batch.channelID=channel.channelID AND batch.marketID=market.marketID

谢谢


如果我理解正确,我需要写如下:

π...(Batch⋈                                   Channel⋈                                Market
           (batch.channelID=channel.channelID)        (batch.marketID=market.marketID)

First time i encounter a relational algebra for databases question today, and i can't seem to find the answer.

I have 3 tables, Batch, Channel and Market.

Batch is connected to Channel and Market by foregein keys (channelID, marketID).

What is the correct notation for a query of this sort:

select * from batch, channel, market 
where batch.channelID=channel.channelID AND batch.marketID=market.marketID

Thanks


If i understood correctly, i need to write as follows:

π...(Batch⋈                                   Channel⋈                                Market
           (batch.channelID=channel.channelID)        (batch.marketID=market.marketID)

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

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

发布评论

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

评论(1

葵雨 2024-10-14 07:59:14

这将是批量⋈通道⋈市场(自然连接是关联和交换的)。

编辑:由于每个连接的属性名称相同(您将 batch.channelIDchannel.channelID 进行比较),因此您在可以使用自然连接编写查询的情况下,当代表自然连接时,无需在 ⋈ 运算符下方写入 (xxx = yyy)。

您可以将其写为 θ-joins,在这种情况下,您的语法几乎是正确的,但我觉得使用 θ-joins 来表示自然连接有点没有抓住重点。您需要做的更改是,由于 θ-join 不具有关联性,因此您需要添加括号:(batch ⋈ channel) ⋈ market

That would be batch ⋈ channel ⋈ market (natural joins are associative and commutative).

EDIT: since the attribute names are the same for each join (you're comparing batch.channelID with channel.channelID), you're in a situation where the query can be written with natural joins, and there's no need to write (xxx = yyy) beneath the ⋈ operator when it's representing a natural join.

You could write it as θ-joins instead, in which case your syntax would be almost correct, but I feel that using θ-joins to represent natural joins kind of misses the point. The change you need to do is that, since θ-joins are not associative, you need to add brackets : (batch ⋈ channel) ⋈ market

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