这是我的情景,
mysql数据库上的“movies”表,
director_id movie
----------- ------
1 movie1
1 movie2
1 movie3
3 movie4
3 movie5
2 movie6
2 movie7
2 movie8
2 movie9
我怎么能按照他们所拥有的电影数量来降序导演呢?
喜欢这个
2 - > 4部电影
1 - > 3部电影
3 - > 2 mvoies
答案 0 :(得分:3)
SELECT director_id, COUNT(*) as TotalMovies FROM movies
GROUP BY director_id
ORDER BY COUNT(*) DESC
答案 1 :(得分:0)
根据每个Director的记录计数创建一个计算列,并对其进行排序。
即 SELECT Directors,count(DISTINCT director)FROM movies GROUP BY director;