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

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

http://www.nowcoder.com/questionTerminal/a158fa6e79274ac497832697b4b83658

法一:内连接+not in

select film_id as '电影id',title as '名称'
from film
where film_id not in(select f.film_id
from film f inner join film_category fc on f.film_id=fc.film_id)

思考了一下,还有更简单的
法二:左连接+is null

select f.film_id, f.title
from film f left join film_category fc on f.film_id=fc.film_id
where fc.category_id is null
数据分析阿宇君的SQL题解 文章被收录于专栏

数据分析的SQL题目

全部评论
那题目是不是多给了一个表的信息??
1 回复
分享
发布于 2021-12-15 10:20
方法二中,fc.category_id is null和fc.category_id='null',有什么区别? 后面这个语句为啥没没出诶?
1 回复
分享
发布于 2022-03-14 16:08
联易融
校招火热招聘中
官网直投
这题和之前的题不一样的地方在于:1.题目中的表不再是原表,而是给出相应字段 2.不再给出最终表示例 3.给出了多余表来干扰。
4 回复
分享
发布于 2022-09-30 21:44 山西
第一种方法不应该是连接category表和film_category表吗 如下: select f.film_id , f.title from film as f where f.film_id not in (select fc.film_id from category as c inner join film_category as fc on c.category_id = fc.category_id);
点赞 回复
分享
发布于 2021-04-14 11:48
他的要求就是连接
点赞 回复
分享
发布于 2021-06-16 17:16
fc.category_id 不能是空的
点赞 回复
分享
发布于 2021-07-07 15:15
第一个内连接为什么不是select film_id as '电影id',title as '名称' from film where film_id not in(select f.film_id from film f inner join film_category fc on f.film_id=fc.film_id where category_id is not null)
点赞 回复
分享
发布于 2021-12-15 10:21
法一子查询多此一举,直接select film_id from film_category
点赞 回复
分享
发布于 2021-12-29 15:43
怎么没用上第二个表,
点赞 回复
分享
发布于 2022-03-13 20:41
不应该查询category.category_id不在 film_category表内吗,有点懵!
点赞 回复
分享
发布于 2022-03-20 20:18
为什么左连接换位右连接就不对了
点赞 回复
分享
发布于 2023-05-08 22:13 辽宁
一样,一样,嘿嘿
点赞 回复
分享
发布于 2023-08-31 13:24 河北

相关推荐

105 2 评论
分享
牛客网
牛客企业服务