Homework 2 Solutions
Homework 2 Solutions
Homework 2
Assume that there already exist SQL tables for the corresponding relational
schema:
Hotel( hname: string, city: string)
Room( hname: string, rnumber: int, size: int );
Guest( passport: string, name: string, date_of_birth: date )
Booking( hname: string, rnumber: string, passport: string, date_of_stay: date )
b)
select count(*)
from room r, hotel h
where r.hname = h.hname
and h.city = 'Zurich';
c)
select avg(name),date_of_birth
from guest
group by date_of_birth;
d)
select hname
from room r
group by hname
having count(*)>=50;
e)
select passport
from guest g, booking b
where g.passport = b.passport
and rnumber in
(select rnumber from room r, hotel h
where r.hname=h.hname
and r.rnumber = 1
and h.city='Paris');
f)
select hname
from room r,hotel h
where r.hname = h.hname
and h.city = 'Rome'
group by hname
having sum(size)>=10000;
g)
select distinct city
from hotel h1,
(select hname,rnumber
from room r,booking b
where r.rnumber = b.rnumber
and r.hname = b.hname
and r.size >= 50
group by hname,rnumber
having count(*)>=10) h2
where h1.hname = h2.hname;
h)
select hname
from hotel h1
where city='Madrid'
and
(select count(*)
from room r
where r.hname = h1.hname)
> ALL
(select count(*)
from room r, hotel h2
where r.hname = h2.hname
and h2.city = 'Oslo')
Question 2
a)
FEM_EMP ÷ ALL_PROJ_RES_PNOS
e)