Skip to content
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
30 changes: 30 additions & 0 deletions subqueries_lab.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
USE sakila;

-- 1.Determine the number of copies of the film "Hunchback Impossible"
-- that exist in the inventory system.

SELECT COUNT(*) AS total_films
FROM inventory
WHERE film_id = (SELECT film_id FROM film WHERE title = 'Hunchback Impossible');

-- 2.List all films whose length is longer
-- than the average length of all the films in the Sakila database.

SELECT title, length
FROM film
WHERE length > (SELECT AVG(length) FROM film)
ORDER BY length DESC;

-- 3.Use a subquery to display all actors who appear in the film "Alone Trip".

SELECT first_name AS name, last_name AS surname
FROM actor
WHERE actor_id IN
(SELECT actor_id
FROM film_actor
WHERE film_id =
(SELECT film_id
FROM film
WHERE title = 'Alone Trip'));