In this assignment, you will make queries from shared databases:
- Sakila database:
shared_sakila
- Sales database:
shared_sales
- Airport database:
shared_airport
Write all queries in SQL. Use SHOW TABLES
and SHOW CREATE TABLE
statements to understand the schema.
The queries may be simple single-table SELECT
statements, SELECT
statements with subqueries, or queries with inner joins, or queries with left joins and GROUP BY.
Some of the problems are very difficult. Please work on these problems early and bring your questions to class. You are welcome to work in groups but produce and submit your solutions individually.
-
List the names of all actors who have co-starred in the same movies with NATALIE HOPKINS.
-
List the pairs of actors and the number of films they have been in together. Show only the top ten 10 pairs.
-
List the titles of all films on the inventory of Store 2 only, i.e. not found in Store 1.
-
List employees along with the their ages in years today. (Hint: Use the
DATEDIFF
orTIMESTAMPDIFF
function along withNOW()
).) -
List all employees with November birthdays. (HINT: Use the
MONTH
function) -
List all orders placed by employees on their own birthdays. (HINT: You may use the
MONTH
andDAYOFMONTH
functions) -
Show the date with highest number of orders placed.
-
List all days of the year (month and day only) of employee birthdays.
-
List the names of Products that are offered by only a single vendor, including the name of that vendor.
-
List all products, including the name of the vendor that offers it at the lowest price.
-
List all unique pairs of orders that have the same date, customer, and employee. (Hint: 10 pairs)
-
Challenge: show all the triplets of products that appear together on at least 100 unique orders. (Hint: 5 triplets)
-
Challenge: Find the most common list of products on an order (Hint: The same list of 8 products is found on 23 orders. You may find the
GROUP_CONCAT
function helpful. Note that it has anORDER_BY
option).
-
Find the passengers who have never flown. (This may a couple of minutes since the data size is big).
-
For each airline, show the number of airports they fly to or from.
-
List pairs of airlines and the number of airports that they share, limit to the top 10 most connected airlines.