Skip to content

Instantly share code, notes, and snippets.

@Shaddyjr
Created July 17, 2019 15:04
Show Gist options
  • Save Shaddyjr/1e0577c5120b7584f3a32644d2339392 to your computer and use it in GitHub Desktop.
Save Shaddyjr/1e0577c5120b7584f3a32644d2339392 to your computer and use it in GitHub Desktop.
WITH subq (actor_1_id, actor_2_id, film_id) AS
(SELECT p1.actor_id, p2.actor_id, p2.film_id
FROM film_actor p1
JOIN film_actor p2
ON p1.film_id = p2.film_id
AND p1.actor_id < p2.actor_id
)
SELECT actor_1_id, actor_2_id, COUNT(film_id) AS count
FROM subq
GROUP BY actor_1_id, actor_2_id
HAVING COUNT(film_id) = (
SELECT MAX(xxx.mycount)
FROM (
SELECT actor_1_id, actor_2_id, COUNT(film_id) AS mycount
FROM subq
GROUP BY actor_1_id, actor_2_id
) AS xxx
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment