【发布时间】:2014-08-07 21:21:19
【问题描述】:
作为斯坦福数据库 MOOC 中包含的练习,我在使用此查询时遇到问题:
对于同一评论者对同一部电影两次评分并第二次给予更高评分的所有情况,返回评论者的姓名和电影的标题。
本练习使用了三个表格:movie, rating and reviewer。正在使用的系统是SQLite。
movie;
+----------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| mID | int(11) | YES | | NULL | |
| title | text | YES | | NULL | |
| year | int(11) | YES | | NULL | |
| director | text | YES | | NULL | |
+----------+---------+------+-----+---------+-------+
rating;
+------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+-------+
| rID | int(11) | YES | | NULL | |
| mID | int(11) | YES | | NULL | |
| stars | int(11) | YES | | NULL | |
| ratingDate | date | YES | | NULL | |
+------------+---------+------+-----+---------+-------+
reviewer;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| rID | int(11) | YES | | NULL | |
| name | text | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
Expected Query Result:
name title
Sarah Martinez Gone with the Wind
如果有人也想要数据,here it is。
【问题讨论】:
-
到目前为止你有没有尝试过?对于这个查询,您考虑了哪些方面?
-
你到底有什么“麻烦”?
-
我想了很多,我知道如何获得对同一部电影两次评分的评论者,但我不知道如何应用条件“并给它第二次更高的评分”
-
@DourHighArch 看看上面的评论,问题在于查询的逻辑结构,如果我掌握了步骤,我猜语法不会是问题