[英]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.