Skip to content

Add files via upload #31

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

Open
wants to merge 1 commit into
base: master
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
22 changes: 22 additions & 0 deletions [Davi]sql-self-cross-join.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Get all pairs of actors that worked together.
USE SAKILA;
SELECT DISTINCT A1.ACTOR_ID AS ACTOR_ID, A1.FIRST_NAME AS ACTOR1_FIRST_NAME, A1.LAST_NAME AS ACTOR1_LAST_NAME,
A2.ACTOR_ID AS ACTOR2_ID, A2.FIRST_NAME AS ACTOR2_FIRST_NAME, A2.LAST_NAME AS ACTOR2_LAST_NAME
FROM FILM_ACTOR FA1
JOIN FILM_ACTOR FA2 ON FA1.FILM_ID = FA2.FILM_ID AND FA1.ACTOR_ID < FA2.ACTOR_ID
JOIN ACTOR A1 ON FA1.aCTOR_ID = A1.ACTOR_ID
JOIN ACTOR A2 ON FA2.ACTOR_ID = A2.ACTOR_ID;


-- Get all pairs of customers that have rented the same film more than 3 times
SELECT FILM_ID, CUSTOMER_ID
FROM RENTAL R
INNER JOIN INVENTORY I
ON R.INVENTORY_ID = I.INVENTORY_ID
GROUP BY FILM_ID, CUSTOMER_ID
HAVING COUNT(*) >= 3;

-- Get all possible pairs of actors and films.
SELECT A.ACTOR_ID, A.FIRST_NAME, A.LAST_NAME, F.FILM_ID, F.TITLE
FROM ACTOR A
CROSS JOIN FILM F;