diff --git a/sql_joins_myfile.sql b/sql_joins_myfile.sql new file mode 100644 index 0000000..2825056 --- /dev/null +++ b/sql_joins_myfile.sql @@ -0,0 +1,42 @@ +-- 1. List the number of films per category. + +SELECT c.category_id as cat, COUNT(c.film_id) as number_of_films FROM sakila.film AS f +JOIN sakila.film_category AS c +ON c.film_id = f.film_id +GROUP BY cat; + + +-- 2. Retrieve the store ID, city, and country for each store. + +SELECT +s.store_id as store, +c.city_id as city, +co.country_id as country +FROM sakila.store AS s +JOIN sakila.address as a +ON s.address_id = a.address_id +JOIN sakila.city AS c +ON a.city_id = c.city_id +JOIN sakila.country AS co +ON c.country_id = co.country_id; + + + +-- 3. Calculate the total revenue generated by each store in dollars. + +SELECT store.store_id, SUM(payment.amount) AS total_revenue +FROM store +JOIN staff ON store.store_id = staff.store_id +JOIN payment ON staff.staff_id = payment.staff_id +GROUP BY store.store_id; + + + +-- 4. Determine the average running time of films for each category. + + +SELECT category.name, ROUND(AVG(film.length), 2) AS average_running_time +FROM category +JOIN film_category ON category.category_id = film_category.category_id +JOIN film ON film_category.film_id = film.film_id +GROUP BY category.name; \ No newline at end of file