Find the description name including the category name and the number of movies corresponding to the movies of the robot, and also need the number of movies corresponding to the category> = 5
The film table is a movie table, the category table is a movie classification table, and the film_category table is an intermediate table between a movie table and a movie classification table (many-to-many intermediate table)
film table
Field | Explanation |
film_id | Movie id |
title | Movie title |
description | Movie description information |
film_id smallint(5) NOT NULL DEFAULT '0',
title varchar(255) NOT NULL,
description text,
PRIMARY KEY (film_id));
category table
Field | Explanation |
category_id | Movie category id |
name | Movie category name |
last_update | Movie Category Last Update Time |
category_id tinyint(3) NOT NULL ,
name varchar(25) NOT NULL, `last_update` timestamp,
PRIMARY KEY ( category_id ));
film_category table
Field | Explanation |
film_id | Movie id |
category_id | Movie category id |
last_update | The last update time of the correspondence between movie id and category id |
film_id smallint(5) NOT NULL,
category_id tinyint(3) NOT NULL, `last_update` timestamp);
SELECT c.name, COUNT(f.film_id) AS amount FROM film AS f, film_category AS fc, category AS c, (SELECT category_id FROM film_category GROUP BY category_id HAVING COUNT(category_id) >= 5) AS cc WHERE f.description LIKE '%robot%' AND f.film_id = fc.film_id AND fc.category_id = c.category_id AND c.category_id = cc.category_id