Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

BUS 440 Database Management

Query the Sakila Schema using MySQL

Description:

In this assignment, you will use the Sakila schema. You will use the provided ERD from an earlier class to create business rules and code SQL programs. You will submit all business rules and a script of your SQL code.

Instructions:

Part 1:

1.   Launch MySQL Workbench and review the Sakila schema.

2.   Review the EER for the Sakila schema again.

3.   Review these possible business rules.

An actor can star in many films, and a film can involve many actors. A film can be categorized by one to many categories, and a category can

categorize many films.

A language is used in one to many films.

A country contains one to many cities.

A city has one to many addresses, but an address belongs to one and only one city. One address can have many stores.

A rental can have many payments.

One film is stored in one to many places in inventory (store).

A staff member can issue one to many rentals.

A staff member is associated with one to many payments.

4.  Add at least five other new business rules here.

Part 2:

5.   Use the ERD to create several SQL programs to view and extract the data.

a.  Tell MySQL Workbench which schema to use. USE sakila;

b.   Create a SQL program to get an aggregate count of the number of films in this database.

c.   Create  a  SQL  program to  determine the  count  of films that  include  actor  Nick Wahlberg.

d.  Write another program that lists the films are that have a PG rating.

e.   Create a SQL program to extract the total amount of revenue received (payment amount) per store manager (staff). Sort by store manager id.

f.   Write a SQL program to display the average revenue grouped by store. Format the results  to  two  decimal  places  and  sort  by  the  results  by  average  revenue  in descending order.

g.   Create a SQL program which extracts and groups the total count of films by rating and the ORDER BY clause to sort the results in descending order by film count. After running the program, which rating had the highest film count?

h.   Display the count of all films grouped by rating. Use a subquery (inner query) to calculate the total count for all films.

i.    Create a program that selects all films whose title begins with a” and has a fourth letter “d” .

j.    Use a regular expression with the [] symbols to display all film titles having a k or q in them.

k.   Use the sample solution below to write a query to show overdue film rentals. Search for films with a return date that is NULL and where the rental date is farther in the past than the rental duration specified in the film table. If so, the film is overdue, and the query should produce the name of the overdue film rental, along with the customer name, phone number, and how many days the rental is overdue. Use CONCAT to concatenate  the  last  and  first  names  of  the  customer,  the  CURRENT_DATE() function to determine the current date, ISNULL to find the movies where the rental return date is null, DATEDIFF and INTERVAL to calculate the days overdue, ORDER BY to sort the results by title.  Limit the results to five rows.

l.    Create a SQL program using GROUP BY to show customers who owe more than $200 with ROLLUP.

m.  Create a SQL program  using  PARTITION to show payment amounts by rentals partitioned over customer. For each rental, include customer first name, last name, payment  amount,  and  payment  date.  Show  the  Total  Payment  Amount  as  the partitioned column.

6.   Click the Save icon in the toolbar to name and save your SQL to a script file. Submit this document and the script file to Moodle.