Created
September 30, 2018 00:02
-
-
Save monorkin/99bd6a1c30b3add5bbd7181f615d13e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Replace with your SQL Query | |
SELECT | |
a1.first_name || ' ' || a1.last_name AS first_actor, | |
a2.first_name || ' ' || a2.last_name AS second_actor, | |
film.title AS title | |
FROM film | |
JOIN film_actor AS fa1 ON fa1.film_id = film.film_id | |
JOIN film_actor AS fa2 ON fa2.film_id = film.film_id | |
AND fa1.actor_id <> fa2.actor_id | |
JOIN actor AS a1 ON fa1.actor_id = a1.actor_id | |
JOIN actor AS a2 ON fa2.actor_id = a2.actor_id | |
WHERE ARRAY[fa1.actor_id, fa2.actor_id] <@ ARRAY( | |
SELECT | |
fa1.actor_id AS id | |
FROM film_actor AS fa1 | |
JOIN film_actor AS fa2 ON fa1.film_id = fa2.film_id | |
AND fa1.actor_id <> fa2.actor_id | |
GROUP BY fa1.actor_id, fa2.actor_id | |
ORDER BY COUNT(1) DESC, fa1.actor_id ASC, fa2.actor_id ASC | |
LIMIT 2 | |
) AND a1.actor_id < a2.actor_id | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment