我有一张桌子,列出了某位演员出演过的电影。表格如下所示:
CELEB | MOVIE
------------------------------------------
Pamela Anderson | Borat: Cultural Learnings of America for Make Benefit Glorious Nation of Kazakhstan
Pamela Anderson | The Flintstones: Little Big League
Pamela Anderson | Pauly Shore Is Dead
Pamela Anderson | Roast of Pamela Anderson: Uncensored
Pamela Anderson | Snapdragon
Jerry Seinfeld | The Ratings Game
Jerry Seinfeld | Pros & Cons
Jerry Seinfeld | Hindsight Is 20/20
每个名人都出演的每部电影都会继续列表。现在我正在尝试编写SQL查询来查找每个演员出演的电影数量。我知道如何列出所有电影一个特定的演员已经完成了:
Select COUNT(MOVIE)
From MOVIES_TABLE
Where CELEB = "Jerry Seinfeld"
但我不知道如何列出每个演员所做的电影数量,然后按降序排列。
答案 0 :(得分:2)
GROUP BY
可让您获得每个名人的汇总数据。 COUNT(*)
为您提供总数#。
select CELEB, count(*) as NUM_MOVIES
from MOVIES_TABLE
group by CELEB
order by NUM_MOVIES desc
答案 1 :(得分:1)
由名人GROUP BY
来查找每个名人的点数,然后按照这样的降序排列计数:
select celeb, count(*) number_of_movies
from movies
group by celeb
order by number_of_movies desc;