时间:2021-07-01 10:21:17 帮助过:74人阅读
推荐:《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使用技巧之行类视图子查询的详细内容,更多请关注Gxlcms其它相关文章!