SQL 3表联接

纳普

桌子 film

film_id title description rental_rate

桌子 category

category_id name last_update

桌子 film_category

film_id category_id last_update

我有SQL选择租金率最喜欢的5个

SELECT title, rental_rate FROM film ORDER BY rental_rate DESC LIMIT 5

基于上面的SQL,如何选择4个最喜欢的类别?

我想要的结果就是 category.name

付款人阿罕默德

尝试这个:

select * from (select t3.name,sum(t1.rental_rate) as rate from film as t1
inner join film_category as t2 on t1.film_id=t2.film_id
inner join category as t3 on t2.category_id=t3.category_id
group by t2.category_id) as detail order by rate DESC LIMIT 5

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章