SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
SELECT JSON_OBJECT( 'films_by_category', JSON_ARRAYAGG( JSON_OBJECT('category_name', c.name, 'film_count', COUNT(film_id)) ) ) AS films_by_category FROM film AS f JOIN film_category fc ON f.film_id = fc.film_id join category c using(category_id) GROUP BY c.name ORDER BY COUNT(f.film_id) DESC;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear