COMP2400 Relational Databases

Question

1.

The relational database moviedb has the following database schema:

Movie(title, production year, country, run time, major genre)

primary key : ftitle, production yearg

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

Person(id,  rst name, last name, year born)

primary key : fidg

Award(award name, institution, country)

primary key : faward nameg

Restriction Category(description, country)

primary key : fdescription, countryg

Director(id, title, production year)

primary key : ftitle, production yearg

foreign keys : [title, production year] Movie[title, production year] [id] Person[id] 

Writer(id, title, production year, credits)

primary key : fid, title, production yearg

foreign keys : [title, production year] Movie[title, production year] [id] Person[id]

Crew(id, title, production year, contribution)

primary key : fid, title, production yearg

foreign keys : [title, production year] Movie[title, production year] [id] Person[id]

Scene(title, production year, scene no, description) primary key : ftitle, production year, scene nog

foreign keys : [title, production year] Movie[title, production year]

Role(id, title, production year, description, credits) primary key : ftitle, production year, descriptiong

foreign keys : [title, production year] Movie[title, production year] [id] Person[id]

Restriction(title, production year, description, country)

primary key : ftitle, production year, description, countryg

foreign keys : [title, production year] Movie[title, production year]

[description, country] Restriction Category[description, country]

Appearance(title, production year, description, scene no)

primary key : ftitle, production year, description, scene nog

foreign keys : [title, production year, scene no] Scene[title, production year, scene no] [title, production year, description] Role[title, production year, description]

Movie Award(title, production year, award name, year of award,category, result) primary key : ftitle, production year, award name, year of award, categoryg foreign keys : [title, production year] Movie[title, production year]

[award name] Award[award name]

Crew Award(id, title, production year, award name, year of award, category, result) primary key : fid, title, production year, award name, year of award, categoryg foreign keys : [id, title, production year] Crew[id, title, production year]

[award name] Award[award name]

Director Award(title, production year, award name, year of award, category, result) primary key : ftitle, production year, award name, year of award, categoryg foreign keys : [title, production year] Director[title, production year]

 [award name] Award[award name]

Writer Award(id, title, production year, award name, year of award, category, result) primary key : fid, title, production year, award name, year of award, categoryg foreign keys : [id, title, production year] Writer[id, title, production year]

[award name] Award[award name]

Actor Award(title, production year, description, award name, year of award,category,result) primary key : ftitle, production year, description, award name, year of award, categoryg foreign keys : [award name] Award[award name]

[title,production year,description]  Role[title,production year,description]

There are ve di erent categories of awards: movie awards, crew awards, director awards, writer awards and actor awards. A movie can only win an award after being nominated for the award.

Your task is to answer the following questions using SQL queries. For each question, your answer must be a single SQL query that may contain subqueries, and you must write and save your queries into the template le myqueries.sql.

1.1 Which awards are there in USA? List these award names.

1.2 Which comedy movies (i.e., the major genre of the movie is comedy) were produced in 1994? List their titles.

1.3 Who played at least one role in movies produced in 1995? List their ids,  rst and last names.

1.4 How many directors have directed at least one movie written by themselves? List that number.

1.5 Which movies had the ‘PG’ restriction in at least two countries? List their titles, production years and the corresponding number of countries with the ‘PG’ restriction.

1.6 Who have written exactly two American movies (i.e., the production country is USA)? List their ids,  rst and last names. Order your results in the ascending order of their ids.

1.7 How many directors have never played any roles in movies directed by themselves? List that number.

1.8 Which crew member(s) worked on the greatest number of movies? List their id(s),  rst and last names.

1.9 Who received the greatest number of nominations for a writer award but never won? List their id(s). 

1.10 Find all the pairs of crew members who won a crew award at the same age. List the pairs of their ids. Note that the result should not contain duplicated pairs of ids, e.g., (id1, id2) and (id2, id1) are considered as duplicated pairs and your query should only produce one of them in the result. Hint: if Emily (born in 1960) won a crew award in 1995 and Tom (born in 1955) won a crew award in 1990, they are considered as a pair of crew members who won a crew award at the same age (=35).