我想找到使用DERIVED表执行最多电影数量的演员的名字。这个错误是怎么出来的?
我的查询
select actor from
(
select distinct(actor.first_name) as 'actor',count(film.film_id) as 'film_count' from actor
join film_actor on film_actor.actor_id=actor.actor_id
join film on film.film_id=film_actor.film_id
group by actor
order by film_count
) as t
where film_count=(select max(film_count) from t);
答案 0 :(得分:0)
SELECT actor FROM
(
SELECT DISTINCT(actor.first_name) AS 'actor',
COUNT(film.film_id) AS 'film_count'
FROM
actor
JOIN
film_actor
ON film_actor.actor_id=actor.actor_id
JOIN
film ON
film.film_id=film_actor.film_id
GROUP BY actor.first_name
ORDER BY film_count
) AS t order by film_count desc
LIMIT 1
您不能直接在子查询外的where
子句中引用子查询中创建的表't'。而是使用上面的查询。我已经按照降序排列了film_count列的结果,并采取了第一行来获得最大数量为film_count的演员