如何在关系代数中表示我的连接?
我是关系代数的新手,对于我的作业,我必须创建两个。 我已经写出了我在 SQL 中遇到的问题,但我不确定如何在关系代数中表示这种连接。 任何帮助/指示将不胜感激。
SELECT ps.FirstName AS StudentFirstName, ps.LastName AS StudentLastName, pst.FirstName AS StaffFirstName , pst.LastName AS StaffLastName, pg.FirstName AS GuardianFirstName, pg.LastName AS GuadianLastName, i.DateTimeReported, i.NatureOfIllness
FROM Incident i
JOIN Student s USING (StudentID)
JOIN Person ps ON (s.StudentID = ps.PersonID)
JOIN Staff st USING (StaffID)
JOIN Person pst ON (st.StaffID = pst.PersonID)
JOIN Guardian g USING (GuardianID)
JOIN Person pg ON (g.GuardianID = pg.PersonID)
WHERE i.DecisionMade IS NULL;
I am new to relational algebra and for my assignment I have to create two. I have written out the problem I have faced in SQL but I am unsure of how to represent such joins in relational algebra. Any help/pointers would be greatly appreciated.
SELECT ps.FirstName AS StudentFirstName, ps.LastName AS StudentLastName, pst.FirstName AS StaffFirstName , pst.LastName AS StaffLastName, pg.FirstName AS GuardianFirstName, pg.LastName AS GuadianLastName, i.DateTimeReported, i.NatureOfIllness
FROM Incident i
JOIN Student s USING (StudentID)
JOIN Person ps ON (s.StudentID = ps.PersonID)
JOIN Staff st USING (StaffID)
JOIN Person pst ON (st.StaffID = pst.PersonID)
JOIN Guardian g USING (GuardianID)
JOIN Person pg ON (g.GuardianID = pg.PersonID)
WHERE i.DecisionMade IS NULL;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在执行的那些左连接在关系代数中称为 theta 连接,有时更具体地称为等连接。 您需要使用看起来像领结的符号,并在其下方写入“StudentID = PersonID”(对于示例中的第二个连接)。 我无法使用花哨的符号,但是 http://en.wikipedia .org/wiki/Relational_algebra#.CE.B8-join_and_equijoin 有一些示例。
另外,6 路连接没有任何问题,而且它们确实会在现实世界中发生。
Those left joins you're doing are referred to in relational algebra as theta-joins, sometimes more specifically specifically as equijoins. You'll want to use the symbol that looks like a bow tie and write "StudentID = PersonID" underneath it (for the second join in your example). I can't do the fancy symbols, but http://en.wikipedia.org/wiki/Relational_algebra#.CE.B8-join_and_equijoin has some examples.
Also, there's nothing wrong with 6-way joins and they'll indeed happen in the real world.
我认为你解决这个问题的方式是错误的。 在现实世界中,您永远不会想要创建 6 路连接的情况。
这里看起来像是事件和人。 人民有自己的角色。 也许应该有三个表:事件、角色和人员。 你两次加入对抗Person的方式将会变得一团糟。
我认为您应该坐下来阅读有关数据库规范化的内容。
http://en.wikipedia.org/wiki/Database_normalization
I think you are going about the problem the wrong way. In the real world you'd never want to create a situation where you had a 6 way join.
What it seems like you have here are incidents and people. The people have roles. There should be maybe three tables, incidents, roles, and people. The way you're joining against Person twice, is going to be a mess.
I think you should sit down and read about database normalization.
http://en.wikipedia.org/wiki/Database_normalization