Docum 3
Docum 3
a) Find name and surname of each employee born after 1982 who has never worked in theme parks
located in France.
b) Find surname and birth date of each Italian employee who has worked in at least 3 carousels of type
aquatic in May 2022.
c) For each theme park that has sold more than 10000 tickets for roller coaster-type carousels, find the
name and the city of the theme park and the total number of employees who has worked in the park.
2. Given the following relational schema (primary keys are underlined, optional
attributes are denoted as ‘*’):
TRAINER (SSN, TName, TSurname, TCity)
GYM (GCode, GName, GCity, Address)
SPECIALTY (SCode, SName, Description)
LESSON (SSN, GCode, Date, SCode, ParticipantsNumber)
a) Show SSN, name and surname of every personal trainer who gave lessons in at least 3 different
gyms located in Turin.
b) Show SSN and surname of every personal trainer who gave at least 10 lessons on Karate, but who
never gave lessons on Judo
c) For each gym, show the name and the total number of lessons given by personal trainers who gave
lessons in at least 3 different gyms located in Turin.
1
DB
MG
Database systems Homework 2: SQL Exercises
SOLUTIONS
1. Given the following relational schema (primary keys are underlined, optional
attributes are denoted as ‘*’):
EMPLOYEE (SSN, Name, Surname, BirthDate, Nationality)
THEME_PARK (TPCode, ParkName, Address, City, Country)
CAROUSEL (CCode, TPCode, CarouselName, CarouselType)
EMPLOYEE_WORK (SSN, Date, CCode, TPCode)
TICKETS (Date, CCode, TPCode, NumTickets)
a) Find name and surname of each employee born after 1982 who has never worked in theme parks
located in France.
b) Find surname and birth date of each Italian employee who has worked in at least 3 carousels of type
aquatic in May 2022.
2
DB
MG
Database systems Homework 2: SQL Exercises
c) For each theme park that has sold more than 10000 tickets for roller coaster-type carousels, find the
name and the city of the theme park and the total number of employees who has worked in the park.
2. Given the following relational schema (primary keys are underlined, optional
attributes are denoted as ‘*’):
TRAINER (SSN, TName, TSurname, TCity)
GYM (GCode, GName, GCity, Address)
SPECIALTY (SCode, SName, Description)
LESSON (SSN, GCode, Date, SCode, ParticipantsNumber)
a) Show SSN, name and surname of every personal trainer who gave lessons in at least 3 different
gyms located in Turin.
Alternative solution:
3
DB
MG
Database systems Homework 2: SQL Exercises
b) Show SSN and surname of every personal trainer who gave at least 10 lessons on Karate, but who
never gave lessons on Judo
Alternative solution:
c) For each gym, show the name and the total number of lessons given by personal trainers who gave
lessons in at least 3 different gyms located in Turin.
4
DB
MG