题解 |

使用子查询的方式找出属于Action分类的所有电影对应的title,description

https://www.nowcoder.com/practice/2f2e556d335d469f96b91b212c4c203e

# 子查询k1-----先查询各电影id的最新分类
select film_id, category_id	
from film_category f
where last_update = (
    select max(last_update) max_date 
    from film_category 
    where (film_id, category_id) = (f.film_id, f.category_id)
)

# 完整查询-----查询属于Action分类的所有电影对应的title,description
select title, description
from (
    select * 
    from category 
    where name = 'Action'
) k1
join (
    select film_id, category_id	
    from film_category f
    where last_update = (
        select max(last_update) max_date 
        from film_category 
        where (film_id, category_id) = (f.film_id, f.category_id)
    )
) k2
on k1.category_id = k2.category_id 
join film f
on f.film_id = k2.film_id;

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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