Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved lab #296

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions labsql4.sql
Original file line number Diff line number Diff line change
@@ -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;