Lecture 5
Lecture 5
! "$# %&('(#*),+- ./0(0
SQL:
Select person_name
From
works
Where company_name = FBC
b List the names of the persons who work for company FBC along with the cities they live in.
Relational algebra:
123 546784:9;<
= >! " # %&(' # *),+- ./0
?:@ 7ABCDFEHGI
123 546784:9;KJLICD
M
= N OP(5 ?:@ 7ABCDFEHG:0
SQL:
Select lives.person_name, city
From
works, lives
Where company_name = FBC and
works.person_name = lives.person_name
c Find the persons who work for company FBC with a salary of more than 10000. List the names of these
persons along with the streets and cities where they live.
Relational algebra:
Q 776 GR:S7T:4:9;<
=! " # %&(' # VUF678W50
123 XYC @ 9YCZ[ 2 \
>](>^$_````5 Q 776 GR:S7T:4:9;50
M
123 XYC @ 9YCZ[ 2 aJLICD
SQL:
Select lives.person_name, stree, city
From
lives, works
Where lives.person_name = works.person_name and salary > 10000
and works.company_name = FBC
d Find the names of the persons who live and work in the same city.
Relational algebra:
XF678WB6 2 RC 6 GI
N OP(5VUF678W,JLI:6 2 CHG0
M
= >OP((" OP(5VXF678WB6 2 RC 6 G
CD 0(0
SQL:
Select person_name
From
works, lives, locates_in
Where works.person_name = lives.person_name and
works.company_name = located_in.company_name and
located_in.city = lives.city
e Find the names of the persons who live in the same city and on the same street as their managers.
Relational algebra:
8( "
,CD50 JL R
3 2 G 2
Z 7:0
CD50
[ 23 8[7887;C8A<
= P!P!" P!P OP((" OP(
70
M
= [ 23 8[7887;C8A 0
SQL:
Select e.person_name
From
lives e, lives m, managers
Where e.person_name = managers.person_name and
m.person_name = managers.manager_name and
e.street = m.street and e.city = m.city
f Find the names of the persons who do not work for company FBC.
Relational algebra:
Q 776 G46784:9;<
(( " # %&(' # VUF678W50
XF678W Q 776 GR\
= 5VUF678W50
M
XF678W Q 776 GR Q 776 G46784:9;
SQL:
Select person_name
From
works
Where person_name not in (Select person_name
From
works
Where company_name = FBC)
g Find the persons whose salaries are more than the salary of everybody who work for company SBC.
Relational algebra:
[ 2 2 RC :S7T[ 9;K
=R]( ! " # &(' # VUF678W50
XF678WXYC @ [ 2 2 8AS7T[59;,
UF678W!
" [ 2 2 RC :S7T[ 9;50
2 :GR B8 ?:@F2 GF[86 3 8[59;,
= >](#$ ](5VXF678WXYC @ [ 2 2 8AFS T[59;0
M
= 5VUF678W50% 2 :GR B8 ?:@F2 GF[86 3 8[59;
SQL:
Select person_name
From
works
Where salary > all (Select salary
From
works
Where company_name = SBC)
h Find the names of the companies that is located in every city where company SBC is located in.
Relational algebra: