使用SQLZOO并且无法弄清楚为什么这个代码的一个版本运行以及为什么第二个版本没有运行。有人可以解释为什么有必要使用AS actor而不是COUNT(actors.id)?谢谢你的解释!
工作:
SELECT title, COUNT(actor.id) AS actors FROM actor
JOIN casting ON casting.actorid=actor.id
JOIN movie ON movie.id=casting.movieid
WHERE yr=1978
GROUP BY title
ORDER BY actors DESC
无效:
SELECT title, COUNT(actor.id) FROM actor
JOIN casting ON casting.actorid=actor.id
JOIN movie ON movie.id=casting.movieid
WHERE yr=1978
GROUP BY title
ORDER BY COUNT(actor.id) DESC
答案 0 :(得分:-1)
两种解决方案都有效。您只需要一个条件就可以在SQLZoo中获得正确的答案。因为标准要求你order by
演员的数量,然后标题。因此,您只需将title
添加到您的order by子句中,如下所示:
SELECT title, COUNT(actor.id) FROM actor
JOIN casting ON casting.actorid=actor.id
JOIN movie ON movie.id=casting.movieid
WHERE yr=1978
GROUP BY title
ORDER BY COUNT(actor.id) DESC, title