Redian新闻
>
Question on relational calculus
avatar
Question on relational calculus# Database - 数据库
r*d
1
Have the tables:
employee(fname, lname, ssn)
works(essn,projectno,hours)
how to write the following query in relational calculus
"retrive the names of employees who work on all the project
that 'john smith' works on"?
Thx!
avatar
p*e
2
if you want to get all employees who work on ANY project
that john smith works on then the SQL is:
select e.ess, e.fname, e.lname, wk.projectno, wk.hours
from employee e
inner join works wk on e.ess = wk.essn
inner join
(select distinct w.projectno
from works w inner join employee ref on ref.ess=w.essn
where ref.lname='Smith' and ref.fname='John')
p
on p.projectno = wk.projectno

【在 r******d 的大作中提到】
: Have the tables:
: employee(fname, lname, ssn)
: works(essn,projectno,hours)
: how to write the following query in relational calculus
: "retrive the names of employees who work on all the project
: that 'john smith' works on"?
: Thx!

avatar
p*e
3

If you want to get all employees who work on ANY (not ALL)
projects
that john smith works on, then the SQL is:
There are also other ways to write the SQL. Here is another
one:
Select e1.*, w1.*
from employee e1 inner join works w1 on e1.ssn=w1.essn
inner join works w2 on w1.projectno=w2.projectno
inner join employee e2 on w2.essn=e2.ssn
where e2.fname='john' and e2.lname='smith'

【在 p*****e 的大作中提到】
: if you want to get all employees who work on ANY project
: that john smith works on then the SQL is:
: select e.ess, e.fname, e.lname, wk.projectno, wk.hours
: from employee e
: inner join works wk on e.ess = wk.essn
: inner join
: (select distinct w.projectno
: from works w inner join employee ref on ref.ess=w.essn
: where ref.lname='Smith' and ref.fname='John')
: p

avatar
p*s
4

Relational calculus has two major categories:
tuple relational calculus and domain relational calculus,
First-order logic expression must be used and the BBS doesn't support
the math notations.
Even though SQL follows tuple relational calculus, SQL is NOT relational
calculus. When this guy submit your answer as his homework solution,
TA may give him 0 point. :)

【在 p*****e 的大作中提到】
: if you want to get all employees who work on ANY project
: that john smith works on then the SQL is:
: select e.ess, e.fname, e.lname, wk.projectno, wk.hours
: from employee e
: inner join works wk on e.ess = wk.essn
: inner join
: (select distinct w.projectno
: from works w inner join employee ref on ref.ess=w.essn
: where ref.lname='Smith' and ref.fname='John')
: p

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。