由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - Question on relational calculus
相关主题
请问什么地方有关系代数之类的数据库基础理论知识啊?紧急请教SQL tuning高手一个问题
PostgreSQL question菜鸟问.asp 里的select语句在基于SQL sever和Access语法上的不
Questions on SQL谁给我优化一下把重复的产品下架的SQL
PB SQL语句的简单问题问个SQL问题
Re: help: question on oracle sys_context(). more confused :(请教:如何优化,提取组间最大行
SQL问题求救!!两个SQL语句的区别
请问怎么用sql实现hashSQL copy a table into a new table and add a new column
[转载] strong SQL skills?Urgent SQL problem!
相关话题的讨论汇总
话题: relational话题: calculus话题: works话题: question话题: sql
进入Database版参与讨论
1 (共1页)
r******d
发帖数: 1
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!
p*****e
发帖数: 58
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!

p*****e
发帖数: 58
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

p****s
发帖数: 3184
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

1 (共1页)
进入Database版参与讨论
相关主题
Urgent SQL problem!Re: help: question on oracle sys_context(). more confused :(
Quick way to learn database?SQL问题求救!!
SQL老学不好请问怎么用sql实现hash
Job Opening - SQL Developer[转载] strong SQL skills?
请问什么地方有关系代数之类的数据库基础理论知识啊?紧急请教SQL tuning高手一个问题
PostgreSQL question菜鸟问.asp 里的select语句在基于SQL sever和Access语法上的不
Questions on SQL谁给我优化一下把重复的产品下架的SQL
PB SQL语句的简单问题问个SQL问题
相关话题的讨论汇总
话题: relational话题: calculus话题: works话题: question话题: sql