Home > Database > Mysql Tutorial > Mysql usage tips: view-like subquery

Mysql usage tips: view-like subquery

藏色散人
Release: 2020-04-20 11:47:14
forward
2471 people have browsed it

The search description information includes the category name and the number of movies corresponding to robot movies, and the number of movies corresponding to the category is also required >= 5

Recommendation: "mysql video tutorial

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 the movie table and the movie classification table (a many-to-many intermediate table)

film Table

Mysql usage tips: view-like subquery##

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));
Copy after login

                                                                                                     

category table

Mysql usage tips: view-like subquery

CREATE TABLE category  (
category_id  tinyint(3)  NOT NULL ,
name  varchar(25) NOT NULL, `last_update` timestamp,
PRIMARY KEY ( category_id ));
Copy after login

film_category table

Mysql usage tips: view-like subquery

CREATE TABLE film_category  (
film_id  smallint(5)  NOT NULL,
category_id  tinyint(3)  NOT NULL, `last_update` timestamp);
Copy after login
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
Copy after login

The above is the detailed content of Mysql usage tips: view-like subquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template