Assignment 1
Assignment 1
Homework 1
45 points (+7 bonus points)
What to turn in on Canvas:
Write your name at the beginning of the file.
The answers are expected to have the following items: the SQL queries, the
results of running these queries in MySQL database provided, the Relational
Algebra expressions, and the query plans/trees.
Database connection instructions:
1. You will receive an email with your password. The username is your FSU
ID. The password is the same for both SSH and MySQL console. Emails will
be sent to your myFSU email address. If you have not received the mail,
check the spam folder; if the spam folder is empty, let me know about it.
2. Use ssh to connect to bl2.cs.fsu.edu.
3. Run this command in the terminal to open the MySQL console: mysql –u
<your_username> –p (hit Enter) <your_password>. Replace the text in red
(i.e. <your_username> and <your_password>) with our username (FSU ID)
and the password that you received.
4. Run the following command in the MySQL console to open the database:
use film;
5. Start exploring the database (e.g. show tables;) and run some queries (e.g.
select * from movies;)
Homework Description
Consider a database with the following schema:
1. The movies table stores the movies played in theaters throughout the city.
2. The districts table stores the city districts where the movie theaters are located.
3. The theaters table stores movie theaters.
4. The movies2theaters table stores the movies and the corresponding theaters
that play that movie.
5. The theaters2districts table lists the theaters and their districts; note that some
theaters belong to several districts.
Tables like movies2theaters and theaters2districts are sometimes called
“junction” tables. They store foreign keys from main tables and connect them in
this way. Junction tables are not usually meant to store any additional
data/objects.
Before you start answering the questions, it is helpful to understand the schema
and browse the data. You could start by issuing a few trivial select * queries from
tables in the schema (e.g. SELECT * FROM movies;).
You can use your home folder as temporary storage for your queries and result
listings.
Good luck!
1. [2 points] Write a SQL query that lists only the length of all movies with a ‘G'
rating.
2. [2 points] Write a Relational Algebra expression for Question 1.
3. [3 points] Write a SQL query that lists only the phone number and district
name of Landmark Neptune Theatre.
4. [3 points] Write a Relational Algebra expression for Question 3.
5. [3 points] Write a SQL query that lists the distinct movie title, theater name,
district name of movies that are played in the ‘Capitol Hill’ district.
6. [3 points] Write a Relational Algebra expression for Question 5.
7. [4 points] Compose a query plan for the Relational Algebra expression from
Question 6.
8. [4 points] Write a query that finds total number of theaters playing each movie.
Output(Movie name, Theater count).
9. [3 points] Write a query that lists the theater name and average length of
movies shown in the theater.
10. [4 points] Write a query to find the theaters in each district playing movies
greater than the average length of all movies. list district, theater, movie and
length.
11. [7 points] Write a query that lists movie name, rating and length where
rating contains the letter ‘R’ and has a length greater than 100.
12. [7 points] Write a Query to list movie name, movie rating, length, theater
and district for the longest ‘R’ rated movie or any ‘PG’ rated movie.
Bonus questions
13. [3 points] Write a query to list movie, theater and movietime of all movies
played after 19:00:00
14. [4 points] Write a query that shows movie name, theater name, district name
and movie count which shows the movie that was played the most number of
times in each district.