【发布时间】:2012-04-23 10:47:04
【问题描述】:
我正在解决 www.db-class.com 的练习。即使已经很晚了,问题仍然很有趣。我偶然发现了额外的最后一项任务,无法找出解决方案。
SQL方案如下:
create table Movie(mID int, title text, year int, director text);
create table Reviewer(rID int, name text);
create table Rating(rID int, mID int, stars int, ratingDate date);
整个数据库可以获取here
问题如下:
Q12 对于每位董事,返回董事姓名以及 他们导演的获得最高评分的电影的标题 他们所有电影的评分,以及该评分的价值。 忽略导演为 NULL 的电影。
要提供更具体的细节,这里有什么问题:
一个查询
select m.mid, m.title, max(r.stars) as stars
from rating r natural join movie m
where m.director is NOT NULL group by m.mid
返回评分最高的电影的 ID:
101 Gone with the Wind 4
103 The Sound of Music 3
104 E.T. 3
107 Avatar 5
108 Raiders of the Lost Ark 4
另一个查询
select m.director, max(r.stars) as stars
from rating r natural join movie m
where m.director is NOT NULL group by m.director
返回电影评分最高的导演姓名:
James Cameron 5
Robert Wise 3
Steven Spielberg 4
Victor Fleming 4
如何加入查询并为导演获取评分最高的电影的名称和星级:
James Cameron Avatar 5
Robert Wise The Sound of Music 3
Steven Spielberg Raiders of the Lost Ark 4
Victor Fleming Gone with the Wind 4
【问题讨论】: