- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPart1_Solution.sql
More file actions
Latest commit
48 lines (40 loc) · 1.59 KB
/
Copy pathPart1_Solution.sql
File metadata and controls
48 lines (40 loc) · 1.59 KB
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
/* Author @Cody Torgerson
for Plista Analytics Coding Challenge
Solution Part 1 Question 1
Query to Find the name of the actor who has appeared in the most films
and how many appearances where there*/
SELECT first_name, last_name, count(film_actor.actor_id) as Total_Film_APP
From actor
inner join film_actor onactor.actor_id=film_actor.actor_id
group by (film_actor.actor_id)
order bycount(film_actor.actor_id) desc
limit1
;
/* Answer to Part 1 Question 2
Which Store had the longest rental, what was the customers name,
and what movie did they rent for so long? */
SELECTstore.store_id, timediff(return_date,rental_date)as Total_Rental_Time, first_name, last_name, title as Movie_Title FROM customer
inner join rental ONcustomer.customer_id=rental.customer_id
inner join inventory onrental.inventory_id=inventory.inventory_id
inner join store oninventory.store_id=store.store_id
inner join film_text oninventory.film_id=film_text.film_id
group by (Total_Rental_Time)
order by Total_Rental_Time desc
limit2
;
/*Solution to Part 1 Question 3
What are the top 5 films by running time (descending) per film category?
(please use the film name and category name, not IDs).
Bonus points for converting the running time to hours and minutes!
*/
SELECT
title,
CONCAT(length DIV 60, ':',(TIME_FORMAT(length % 60, '%s'))) AS Film_Runtime,
category.nameAS Genre
FROM
film
inner JOIN film_category ONfilm.film_id=film_category.film_id
inner JOIN category ONfilm_category.category_id=category.category_id
group by Film_Runtime with rollup
Order by Genre, Film_Runtime desc
;