关系代数语法
今天我第一次遇到数据库关系代数问题,我似乎找不到答案。
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将是批量⋈通道⋈市场(自然连接是关联和交换的)。
编辑:由于每个连接的属性名称相同(您将
batch.channelID
与channel.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
withchannel.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