一开始我是这样写
select c.name as '分类名称category.name',
count(f.film_id) as '电影数目count(film.film_id)'
from film f,category c,film_category fc
where f.film_id=fc.film_id
and fc.category_id=c.category_id
and f.description like '%robot%'
group by c.name
having count(fc.category_id)>=5很显然对蓝色标记部分理解不对
应该先找到每个电影分类下电影总数量大于5的category_id,修改如下
正确代码
select c.name,
count(fc.film_id)
from film f,category c,film_category fc
where f.description like '%robot%'
and f.film_id=fc.film_id
and fc.category_id=c.category_id
and c.category_id in (select category_id
from film_category
group by category_id
having count(film_id)>=5)
京公网安备 11010502036488号