Posted by Krzysiek, Dec. 17, 2024, 11:53 p.m.
41. Productive actors vs less-productive actors
Why this query does not work for question about. There is a missing two records
WITH actor_status AS (
SELECT
actor_id,
COUNT(film_id) AS nb_of_films
FROM film_actor
GROUP BY actor_id
)
SELECT
CASE
WHEN s.nb_of_films < 30 THEN 'less-productive'
ELSE 'productive'
END AS actor_category,
COUNT(*) AS actor_count
FROM actor_status s
LEFT JOIN actor a ON a.actor_id = s.actor_id
GROUP BY
CASE
WHEN s.nb_of_films < 30 THEN 'less-productive'
ELSE 'productive'
ENDWITH actor_status AS (
SELECT
actor_id,
COUNT(film_id) AS nb_of_films
FROM film_actor
GROUP BY actor_id
)
SELECT
CASE
WHEN s.nb_of_films < 30 THEN 'less-productive'
ELSE 'productive'
END AS actor_category,
COUNT(*) AS actor_count
FROM actor_status s
LEFT JOIN actor a ON a.actor_id = s.actor_id
GROUP BY
CASE
WHEN s.nb_of_films < 30 THEN 'less-productive'
ELSE 'productive'
END