gpt4 book ai didi

mysql - 找到平均电影长度最长的类型。数据库

转载 作者:行者123 更新时间:2023-12-01 00:40:20 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com