题解 | #查找描述信息中包含robot的电影对应的分类名称以及电影数目,而且还需要该分类对应电影数量>=5部#

查找描述信息中包含robot的电影对应的分类名称以及电影数目,而且还需要该分类对应电影数量>=5部

http://www.nowcoder.com/practice/3a303a39cc40489b99a7e1867e6507c5

题目本身不难,难点在读懂题意

查找描述信息(film.description)中包含robot的电影对应的分类名称(category.name)以及电影数目(count(film.film_id)),还需要该分类包含电影总数量(count(film_category.category_id))>=5部

题意可以说是相当具有迷惑性了,加粗的部分这个字段的聚合明显和文字描述不是一个意思

此外要注意的一点是,这个条件是该分类包含的电影总数量大于等于5部,而不是该分类包含robot的电影数量大于5部,所以两个条件应该并列在where后,而不是一个where一个having的递进关系

由于where后不能直接加count聚合函数,所以首先子查询筛选出电影总数量大于5部的类别

select category_id
from film_category
group by category_id
having count(film_id)>=5

接下来就顺理成章的连接查询即可

select category.name, count(film.film_id)
from film 
join film_category fc
on film.film_id = fc.film_id
join category
on category.category_id = fc.category_id
where description like '%robot%'
and fc.category_id in 
    (
    select category_id
    from film_category
    group by category_id
    having count(film_id)>=5
    )
group by category.name;
全部评论

相关推荐

06-17 00:26
门头沟学院 Java
程序员小白条:建议换下项目,智能 AI 旅游推荐平台:https://github.com/luoye6/vue3_tourism_frontend 智能 AI 校园二手交易平台:https://github.com/luoye6/vue3_trade_frontend GPT 智能图书馆:https://github.com/luoye6/Vue_BookManageSystem 选项目要选自己能掌握的,然后最好能自己拓展的,分布式这种尽量别去写,不然你只能背八股文了,另外实习的话要多投,尤其是学历不利的情况下,多找几段实习,最好公司title大一点的
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务