解法练习
案例1.子查询练习
字段 说明
film_id 电影id
title 电影名称
description 电影描述信息
category_id 电影分类id
name 电影分类名称
last_update 电影分类最后更新时间
film_id 电影id
category_id 电影分类id
last_update 电影id和分类id对应关系的最后更新时间
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);使用子查询的方式找出属于Action分类的所有电影对应的title,description 解题命令
select title,description from film where film_id in(select film_id from film_category where category_id in(select category_id from category w where name=‘Action‘)) #子查询解法 select f.title,f.description from film as f inner join film_category as fc on f.film_id = fc.film_id inner join category as c on c.category_id = fc.category_id where c.name = ‘Action‘; #常规解法
名词解释补充
案例1:Explain解释
获取select * from employees对应的执行计划
explain select * from employees