【问题标题】:What is the top movie genre using the average rank per movie genre as the metric?使用每个电影类型的平均排名作为指标的顶级电影类型是什么?
【发布时间】:2020-06-01 19:42:36
【问题描述】:

目前,我正在自学 SQL,遇到了一个非常有趣的问题: 基于 10,000 或更多选票的评分,使用 每个电影类型的平均排名作为指标? (注意:排名值越高被认为是更好的电影)

以下是表格:rating

+---------+------+--------+--------------+
| movieid | rank | votes  | distribution |
+---------+------+--------+--------------+
| 1672052 | 7.8  |   8111 | 0000001222   |
| 1672111 | 5.3  |  32183 | 0001221000   |
| 1672580 | 4.4  |   1894 | 0011110000   |
| 1672716 | 7.0  |   1255 | 0000001212   |
| 1673647 | 6.5  |    128 | 0000111211   |
| 1673658 | 3.9  |     20 | 22101.10.1   |
| 1673848 | 7.0  | 137748 | 0000012211   |
| 1674388 | 5.5  |  47380 | 0001221000   |

表:movie_directores

+---------+------------+-------------+
| movieid | directorid | genre       |
+---------+------------+-------------+
| 1672052 |      22397 | Drama       |
| 1672111 |      54934 | Action      |
| 1672580 |     297253 | Comedy      |
| 1672716 |     188926 | Drama       |
| 1672946 |     188940 | Action      |
| 1673647 |     302682 | Drama       |
| 1673658 |     155385 | Comedy      |
| 1673848 |     133605 | Comedy      |
| 1674388 |     115990 | Adventure   |
| 1674737 |     164962 | Drama       |
| 1677011 |     116812 | Comedy      |
| 1677258 |      99002 | Comedy      |
| 1677346 |      22912 | Biography   |

我想要的是:基于 10,000 或更多投票的评分,我想知道以每种电影类型的平均排名作为指标的顶级电影类型是什么

到目前为止我所做的是:

SELECT movieid
FROM rating m
JOIN (
SELECT movieid, COUNT(movieid) 
FROM rating) 
ON m.movieid = r.movieid
count(*)>=10000

不确定逻辑是否正确。有什么帮助吗?

【问题讨论】:

    标签: mysql sql sqlite join mysql-workbench


    【解决方案1】:

    考虑:

    select md.genre, avg(r.rank) avg_rank
    from movies_directores md
    inner join rating r on r.movieid = md.movieid
    where r.votes > 10000
    group by md.genre
    order by avg(r.rank) desc
    limit 1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-11
      • 2012-12-24
      • 2020-03-24
      • 2018-07-19
      • 2015-07-06
      • 2015-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多