从关系型代数的三个关系中选择 [英] Selecting from three Relation with Relational Algebra
本文介绍了从关系型代数的三个关系中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有此表
Customer{cid, name, phone, address}
Employee{eid, name, positon, salary}
Resp_for{cid,eid}
现在我想在关系代数中询问是否应打印出所有可为客户使用的员工:'Obama'
Now I want to ask in relational Algebra that it should print out all employees that are resposible for the Customer: 'Obama'
我正在尝试,但是不确定我是否清楚地理解关系代数,所以我创建了这个文件:
I am trying it but not sure that I understand the relational algebra clearly, so I create this:
PROJECT (SELECT (Customer x Employeee x Resp_for))
E.eid C.name = 'Obama'
AND R.cid = C.cid
And R.eid = E.eid
那么它如何像sql查询一样?
so how it looks as sql query?
SELECT E.eid
FROM Customer JOIN Employee JOIN Resp_for
WHERE C.name = 'Obama'
AND R.cid = C.cid
And R.eid = E.eid
是正确的吗?
推荐答案
正确的ugh如果不将表别名(R,C和E)放在各自的表上,就不太可能运行。
That is correct, though without putting the table aliases (R, C and E) against their respective tables it is unlikely to run.
有一种新的表示联接的形式,这种形式更常见这些天:
There is a new form for expressing joins which is more common these days:
SELECT E.eid
FROM Customer C
INNER JOIN Resp_for R
ON R.cid = C.cid
INNER JOIN Employee E
ON E.eid = R.eid
WHERE C.name = 'Obama'
相同的含义,不同的格式和恕我直言易于吸收。
Same meaning, different format and IMHO easier to assimilate.
这篇关于从关系型代数的三个关系中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文