From b42187c4f12c9cbd54a104d7f8b0bf530a60d217 Mon Sep 17 00:00:00 2001 From: hlopzz Date: Tue, 17 Dec 2024 17:23:08 -0400 Subject: [PATCH] Add files via upload --- SQL SUBQUERIES/1.sql | 4 ++++ SQL SUBQUERIES/2.sql | 3 +++ SQL SUBQUERIES/3.sql | 8 ++++++++ SQL SUBQUERIES/4.sql | 5 +++++ SQL SUBQUERIES/5.sql | 9 +++++++++ SQL SUBQUERIES/6.sql | 10 ++++++++++ SQL SUBQUERIES/7.sql | 6 ++++++ SQL SUBQUERIES/8.sql | 7 +++++++ 8 files changed, 52 insertions(+) create mode 100644 SQL SUBQUERIES/1.sql create mode 100644 SQL SUBQUERIES/2.sql create mode 100644 SQL SUBQUERIES/3.sql create mode 100644 SQL SUBQUERIES/4.sql create mode 100644 SQL SUBQUERIES/5.sql create mode 100644 SQL SUBQUERIES/6.sql create mode 100644 SQL SUBQUERIES/7.sql create mode 100644 SQL SUBQUERIES/8.sql diff --git a/SQL SUBQUERIES/1.sql b/SQL SUBQUERIES/1.sql new file mode 100644 index 0000000..ba364dc --- /dev/null +++ b/SQL SUBQUERIES/1.sql @@ -0,0 +1,4 @@ +SELECT COUNT(*) AS total_copies +FROM inventory i +JOIN film f ON i.film_id = f.film_id +WHERE f.title = 'Hunchback Impossible'; diff --git a/SQL SUBQUERIES/2.sql b/SQL SUBQUERIES/2.sql new file mode 100644 index 0000000..7c77548 --- /dev/null +++ b/SQL SUBQUERIES/2.sql @@ -0,0 +1,3 @@ +SELECT title, length +FROM film +WHERE length > (SELECT AVG(length) FROM film); diff --git a/SQL SUBQUERIES/3.sql b/SQL SUBQUERIES/3.sql new file mode 100644 index 0000000..dd69046 --- /dev/null +++ b/SQL SUBQUERIES/3.sql @@ -0,0 +1,8 @@ +SELECT a.actor_id, a.first_name, a.last_name +FROM actor a +WHERE a.actor_id IN ( + SELECT fa.actor_id + FROM film_actor fa + JOIN film f ON fa.film_id = f.film_id + WHERE f.title = 'Alone Trip' +); diff --git a/SQL SUBQUERIES/4.sql b/SQL SUBQUERIES/4.sql new file mode 100644 index 0000000..73cf173 --- /dev/null +++ b/SQL SUBQUERIES/4.sql @@ -0,0 +1,5 @@ +SELECT f.title +FROM film f +JOIN film_category fc ON f.film_id = fc.film_id +JOIN category c ON fc.category_id = c.category_id +WHERE c.name = 'Family'; diff --git a/SQL SUBQUERIES/5.sql b/SQL SUBQUERIES/5.sql new file mode 100644 index 0000000..9d32ea6 --- /dev/null +++ b/SQL SUBQUERIES/5.sql @@ -0,0 +1,9 @@ +SELECT first_name, last_name, email +FROM customer +WHERE address_id IN ( + SELECT address_id + FROM address a + JOIN city c ON a.city_id = c.city_id + JOIN country co ON c.country_id = co.country_id + WHERE co.country = 'Canada' +); diff --git a/SQL SUBQUERIES/6.sql b/SQL SUBQUERIES/6.sql new file mode 100644 index 0000000..fe104aa --- /dev/null +++ b/SQL SUBQUERIES/6.sql @@ -0,0 +1,10 @@ +SELECT f.title +FROM film f +JOIN film_actor fa ON f.film_id = fa.film_id +WHERE fa.actor_id = ( + SELECT actor_id + FROM film_actor + GROUP BY actor_id + ORDER BY COUNT(film_id) DESC + LIMIT 1 +); diff --git a/SQL SUBQUERIES/7.sql b/SQL SUBQUERIES/7.sql new file mode 100644 index 0000000..75c5e1c --- /dev/null +++ b/SQL SUBQUERIES/7.sql @@ -0,0 +1,6 @@ +SELECT cu.customer_id, cu.first_name, cu.last_name, SUM(p.amount) AS total_spent +FROM customer cu +JOIN payment p ON cu.customer_id = p.customer_id +GROUP BY cu.customer_id, cu.first_name, cu.last_name +ORDER BY total_spent DESC +LIMIT 1; diff --git a/SQL SUBQUERIES/8.sql b/SQL SUBQUERIES/8.sql new file mode 100644 index 0000000..0106095 --- /dev/null +++ b/SQL SUBQUERIES/8.sql @@ -0,0 +1,7 @@ +SELECT customer_id, SUM(amount) AS total_amount_spent +FROM payment +GROUP BY customer_id +HAVING SUM(amount) > (SELECT AVG(total_amount) + FROM (SELECT SUM(amount) AS total_amount + FROM payment + GROUP BY customer_id) AS subquery);