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