explain analyze
SELECT
c.name category
, sum(CASE WHEN i.store_id = 1 THEN 1 END) AS store_1
, sum(CASE WHEN i.store_id = 2 THEN 1 END) AS store_2
FROM category c
JOIN film_category fc ON c.category_id = fc.category_id
JOIN inventory i ON i.film_id = fc.film_id
JOIN store s ON s.store_id = i.store_id
GROUP BY c.name;
-- show status like '%cost';
explain analyze
SELECT
c.name category
, sum(CASE WHEN i.store_id = 1 THEN 1 END) AS store_1
, sum(CASE WHEN i.store_id = 2 THEN 1 END) AS store_2
FROM category c
JOIN film_category fc ON c.category_id = fc.category_id
JOIN inventory i ON i.film_id = fc.film_id
GROUP BY c.name;
-- show status like '%cost';