![](/img/trans.png)
[英]Write a query to find the full name of the actor who has acted in the third most number of movies in mysql?
[英]Write a query to find the full name of the actor who has acted in the maximum number of movies
您的查询应该做您想做的事,但您需要修复limit
子句。 如果您想要拥有最多电影的一个演员,那么您需要limit 1
而不是limit 2, 1
。 select
子句中的concat()
也需要修复 - 您需要名称之间的空格,而不是它们之前的空格。
另一种选择是使用聚合子查询进行排序,这避免了外部查询中的聚合:
select concat(a.first_name, ' ', a.last_name) as full_name
from actor a
order by (select count(*) from film_actor fa where fa.actor_id = a.actor_id) desc
limit 1
请注意,您的查询和这个查询都没有考虑到顶级关系的可能性。 你的问题没有具体说明。 如果这就是这里需要的,那么策略会有所不同——但这似乎不是你所要求的。
如果您不想使用内部查询并且只使用连接,这就是答案:
SELECT concat(FIRST_NAME," ",LAST_NAME) as full_name FROM ACTOR A INNER JOIN FILM_ACTOR FA on A.ACTOR_ID=FA.ACTOR_ID GROUP BY (FA.ACTOR_ID) ORDER BY count(FA.FILM_ID) DESC LIMIT 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.