a_khuzina

SQL_mistake 2

Jan 21st, 2022 (edited)
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT c.name AS name_category,
  2.        COUNT(mov.film_id) AS total_films
  3. FROM category AS c
  4. LEFT JOIN film_category AS fc ON c.category_id=fc.category_id
  5. LEFT JOIN
  6.   (SELECT DISTINCT m.film_id
  7.    FROM movie AS m
  8.    LEFT JOIN film_category AS fc ON m.film_id=fc.film_id
  9.    LEFT JOIN film_actor AS fa ON fc.film_id=fa.film_id
  10.    WHERE fa.actor_id IN (SELECT a1.actor_id
  11.                          FROM actor AS a1
  12.                          LEFT JOIN film_actor AS fa1 ON a1.actor_id=fa1.actor_id
  13.                          LEFT JOIN movie AS m1 ON fa1.film_id=m1.film_id
  14.                          WHERE m1.release_year > 2013
  15.                          GROUP BY a1.actor_id
  16.                          HAVING a1.actor_id > 7)) AS mov ON fc.film_id=mov.film_id
  17. GROUP BY name_category
  18. ORDER BY total_films DESC
Add Comment
Please, Sign In to add comment