MySQL Workbench查询-在Sakila数据库中查找租用少于5个演员的电影的客户

时间:2018-12-11 01:33:15

标签: mysql mysql-workbench

我正在SQP Workbench中运行此代码。是Sakila数据库。我对SQL查询非常陌生,所以请帮忙。

查找租借电影的演员少于5位的客户。返回客户的名字,客户的姓氏,电影标题和电影中的演员人数。

select customer_id,film_id 
from 
customer c inner join payment p on c.customer_id=p.customer_id
inner 
join rental r on p.rental_id=r.rental_id

inner join inventory i on r.investory_id=i.investory_id

inner join film_category fc on i.film_id=fc.film_id

inner join category c on fc.category_id=c.category_id

inner join film f on fc.film_id=f.film_id

where film_id in(select film_id from(select film_id,count(actor_id) as s 
from
 customer c inner join payment p on c.customer_id=p.customer_id

inner join rental r on p.rental_id=r.rental_id

inner join inventory i on r.investory_id=i.investory_id

inner join film_category fc on i.film_id=fc.film_id

inner join category c on fc.category_id=c.category_id

fc.film_id = f.film_id上的内部连接胶片f     通过具有count(actor_id)<5)的film_id分组;

enter image description here

enter image description here

0 个答案:

没有答案