sqlzoo"更多加入" #15

时间:2016-12-16 22:14:43

标签: sql database

有人能告诉我为什么我的解决方案不能应对这一挑战吗?

http://sqlzoo.net/wiki/More_JOIN_operations

15。列出1978年发布的电影,按演员阵容的数量排序,然后按标题排列。

SELECT title, COUNT(actorid) AS actors FROM movie
JOIN casting ON id = movieid
WHERE yr = 1978
GROUP BY title
ORDER BY actors DESC

3 个答案:

答案 0 :(得分:2)

因为您错过了第二级ORDER BY字词。它应该是:

ORDER BY actors DESC, title

(问题并没有明确要求降序,但他们的官方“正确答案”是这样订购的。)

答案 1 :(得分:1)

由于要求要求您按演员数量和标题排序。因此,您必须在title子句中添加Order by

SELECT title, COUNT(actorid) AS actors FROM movie
 JOIN casting ON id = movieid
 WHERE yr = 1978
 GROUP BY title
 ORDER BY actors DESC, title

答案 2 :(得分:0)

select distinct a1.name from actor a1
join casting c1 on c1.actorid = a1.id
join movie m1 on c1.movieid = m1.id
where m1.id in (
select distinct m.id from movie m
join casting c on c.movieid = m.id
join actor a  on c.actorid = a.id
where a.name = 'Art Garfunkel')
and a1.name <> 'Art Garfunkel'