From 04536c801caef1e002618cb6df1ba48f18809df4 Mon Sep 17 00:00:00 2001 From: ctupac999 Date: Tue, 3 Dec 2024 16:47:17 +0100 Subject: [PATCH] ok --- labsql4.sql | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 labsql4.sql diff --git a/labsql4.sql b/labsql4.sql new file mode 100644 index 0000000..399549e --- /dev/null +++ b/labsql4.sql @@ -0,0 +1,59 @@ +-- 1. List the number of films per category. + +SELECT + c.name AS category_name, + COUNT(f.film_id) AS total_films +FROM + category c +JOIN + film_category fc ON c.category_id = fc.category_id +JOIN + film f ON fc.film_id = f.film_id +GROUP BY + c.name; + +-- 2. Retrieve the store ID, city, and country for each store. + +SELECT + s.store_id, + c.city, + co.country +FROM + store s +JOIN + address a ON s.address_id = a.address_id +JOIN + city c ON a.city_id = c.city_id +JOIN + country co ON c.country_id = co.country_id; + +-- 3. Calculate the total revenue generated by each store in dollars. + +SELECT + s.store_id, + SUM(p.amount) AS total_revenue +FROM + store s +JOIN + inventory i ON s.store_id = i.store_id +JOIN + rental r ON i.inventory_id = r.inventory_id +JOIN + payment p ON r.rental_id = p.rental_id +GROUP BY + s.store_id; + +-- 4. Determine the average running time of films for each category. + +SELECT + c.name AS category_name, + AVG(f.length) AS average_running_time +FROM + category c +JOIN + film_category fc ON c.category_id = fc.category_id +JOIN + film f ON fc.film_id = f.film_id +GROUP BY + c.name; +