/
MavenMovies_Mid_Course_Project.sql
129 lines (80 loc) · 2.52 KB
/
MavenMovies_Mid_Course_Project.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use mavenmovies;
/*
1. We will need a list of all staff members, including their first and last names,
email addresses, and the store identification number where they work.
*/
SELECT
first_name, last_name, email, store_id
FROM
staff;
/*
2. We will need separate counts of inventory items held at each of your two stores.
*/
SELECT
store_id, COUNT(inventory_id) number_of_movies
FROM
inventory
GROUP BY store_id;
/*
3. We will need a count of active customers for each of your stores. Separately, please.
*/
SELECT
store_id,
COUNT(customer_id) AS active_customers
FROM
customer
WHERE active = 1
GROUP BY store_id;
/*
4. In order to assess the liability of a data breach, we will need you to provide a count
of all customer email addresses stored in the database.
*/
SELECT
COUNT(email) AS customer_email_addresses
FROM
customer;
/*
5. We are interested in how diverse your film offering is as a means of understanding how likely
you are to keep customers engaged in the future. Please provide a count of unique film titles
you have in inventory at each store and then provide a count of the unique categories of films you provide.
*/
SELECT
COUNT(DISTINCT film_id) AS unique_film_titles
FROM
film;
SELECT
COUNT(DISTINCT name) AS unique_film_categories
FROM
category;
/*
6. We would like to understand the replacement cost of your films.
Please provide the replacement cost for the film that is least expensive to replace,
the most expensive to replace, and the average of all films you carry. ``
*/
SELECT
MIN(replacement_cost) AS least_expensive_to_replace,
MAX(replacement_cost) AS most_expensive_to_replace,
AVG(replacement_cost) AS average_replacement_cost
FROM
film;
/*
7. We are interested in having you put payment monitoring systems and maximum payment
processing restrictions in place in order to minimize the future risk of fraud by your staff.
Please provide the average payment you process, as well as the maximum payment you have processed.
*/
SELECT
AVG(amount) AS average_payment,
MAX(amount) AS maximum_payment
FROM
payment;
/*
8. We would like to better understand what your customer base looks like.
Please provide a list of all customer identification values, with a count of rentals
they have made all-time, with your highest volume customers at the top of the list.
*/
SELECT
customer_id, COUNT(rental_id) AS number_of_rentals
FROM
rental
GROUP BY customer_id
ORDER BY COUNT(rental_id) DESC;