牛客SQL30
子查询,下面的SQL逻辑很清晰。
最后用film_id查电影表中的title与description
select title,description from film where film_id IN (
#再用查到的categoryid查询对应关系表中的film_id
select film_id from film_category where category_id IN (
#先在分类表中查分类名为Action的category_id
select category_id from category where name = "Action"
)
)
连接查询
select f.title,f.description
from film as f
#电影表与关系表合并
left join film_category as fc
on f.film_id = fc.film_id
#关系表与分类表合并
left join category as c
on fc.category_id = c.category_id
where c.name = "Action";