查找描述信息中包括robot的电影对应的分类名称以及电影数目,而且还需要该分类对应电影数量>=5部
推荐:《mysql视频教程》
film表为电影表,category表为电影分类表,film_category表为电影表与电影分类表的中间表(多对多的中间表)
film表
CREATE TABLE IF NOT EXISTS film ( film_id smallint(5) NOT NULL DEFAULT '0', title varchar(255) NOT NULL, description text, PRIMARY KEY (film_id));
category表
CREATE TABLE category ( category_id tinyint(3) NOT NULL , name varchar(25) NOT NULL, `last_update` timestamp, PRIMARY KEY ( category_id ));
film_category表
CREATE TABLE film_category ( 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
以上就是mysql使用技巧之行类视图子查询的详细内容,更多请关注php中文网其它相关文章!
已抢16590个
抢已抢49550个
抢已抢16874个
抢已抢8990个
抢已抢4587个
抢已抢4598个
抢