From 8d4e41618b75d12c09714aa84516f98077e06243 Mon Sep 17 00:00:00 2001 From: andy-casagrande <163665556+andy-casagrande@users.noreply.github.com> Date: Mon, 17 Jun 2024 13:10:30 +0100 Subject: [PATCH] Add files via upload --- Lab SQL Self and cross join.sql | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Lab SQL Self and cross join.sql diff --git a/Lab SQL Self and cross join.sql b/Lab SQL Self and cross join.sql new file mode 100644 index 0000000..dd8c44b --- /dev/null +++ b/Lab SQL Self and cross join.sql @@ -0,0 +1,20 @@ +-- 1. Get all pairs of actors that worked together. +SELECT FA1.ACTOR_ID AS ACTOR_ID_FIRST, FA2.ACTOR_ID AS ACTOR_ID_SECOND, FA1.FILM_ID +FROM SAKILA.FILM_ACTOR FA1 +INNER JOIN SAKILA.FILM_ACTOR FA2 +ON FA1.FILM_ID = FA2.FILM_ID +AND FA1.ACTOR_ID <> FA2.ACTOR_ID; + +-- Get all pairs of customers that have rented the same film more than 3 times. +SELECT R1.CUSTOMER_ID AS CUSTOMER1, R2.CUSTOMER_ID AS CUSTOMER2, COUNT(*) AS RENTAL_COUNT +FROM SAKILA.RENTAL R1 +JOIN SAKILA.RENTAL R2 +ON R1.INVENTORY_ID = R2.INVENTORY_ID +AND R1.CUSTOMER_ID <> R2.CUSTOMER_ID +GROUP BY CUSTOMER1, CUSTOMER2 +HAVING COUNT(*) > 3; + +-- Get all possible pairs of actors and films. +SELECT Film_actor.ACTOR_ID, Film.FILM_ID, Film.TITLE +FROM SAKILA.FILM_ACTOR Film_actor +CROSS JOIN SAKILA.FILM Film; \ No newline at end of file