我是 SQL 的新手,我试图在 mySQL 上解决这个问题。 这是寻找平均电影长度最长的类型。我在下面列出了流派和电影的长度,但我真的很困惑如何计算每种流派的平均值。类型:
- 行动,
- 喜剧,
- 戏剧,
- 科幻小说,
- 惊悚片和
- 冒险
取个别流派的平均值并显示它们的最大平均值。任何帮助将不胜感激谢谢
SELECT tblGenre.Genre, tblMovie.Length
FROM tblMovie, tblMovieGenre, tblGenre
WHERE (((tblMovie.movie_ID)=[tblMovieGenre].[Movie]) AND ((tblMovieGenre.Genre)=[tblGenre].[genre_ID]))
GROUP BY tblGenre.Genre, tblMovie.Length;
输出
Genre Length
Action 81
Action 97
Action 110
Action 130
Action 136
Action 145
Action 152
Action 165
Adventure 90
Adventure 109
Adventure 111
Adventure 132
Adventure 145
Adventure 178
Adventure 179
Adventure 201
Comedy 87
Comedy 90
Comedy 97
Comedy 109
Comedy 111
Drama 80
Drama 81
Drama 90
Drama 91
Drama 93
Drama 95
Drama 102
Drama 109
Drama 111
Drama 130
Drama 132
Drama 139
Drama 151
Drama 152
Drama 161
Drama 175
Drama 194
Sci-Fi 110
Sci-Fi 136
Sci-Fi 145
Thriller 84
Thriller 91
Thriller 93
Thriller 99
Thriller 110
Thriller 151
Thriller 165
最佳答案
我不太了解MySQL,但如果我理解正确,这就是你想要的:
SELECT tblGenre.Genre, AVERAGE(tblMovie.Length)
FROM tblMovie, tblMovieGenre, tblGenre
WHERE (((tblMovie.movie_ID)=[tblMovieGenre].[Movie]) AND ((tblMovieGenre.Genre)=[tblGenre].[genre_ID]))
GROUP BY tblGenre.Genre
ORDER BY 2 desc
limit 1;
关于mysql - 找到平均电影长度最长的类型。数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34125465/