题解 | #使用join查询找出没有分类的电影id以及名称#

使用join查询方式找出没有分类的电影id以及名称

https://www.nowcoder.com/practice/a158fa6e79274ac497832697b4b83658

# select film_id,title from film where film_id not in
# (select t2.film_id from
# (select category_id,name,rank()over(partition by category_id order by last_update desc) rd1 from category) t1
# join
# (select film_id,category_id,rank()over(partition by film_id order by last_update desc) rd2 from film_category)t2
# on t1.category_id=t2.category_id
# where t1.rd1=1 and t2.rd2=1
# )
#以上为方法1,比较复杂,实际上用到左连接+is null来解题会非常简单
select film.film_id,film.title from film left join film_category on film.film_id=film_category.film_id where film_category.category_id is null

我一开始用的方法一进行解题,可以成功运行、但是代码很多、逻辑很复杂

遇到筛选 一个表中的数据在另一个表中没有出现的数据时 用到表连接+is null会很简单

全部评论

相关推荐

11-14 16:15
已编辑
湖南工业大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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