我正在解决www.db-class.com练习。即使时间晚了,问题仍然很有趣。我偶然发现了最后一项任务,无法找出解决方案。来自www.db-class.com的SQL查询
的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);
整个数据库可以obtainted here
的问题如下:
Q12对于各家所长,回报导演的名字连同他们指导的电影名称( )在其所有电影中获得最高评级 ,而val该等级的评级。 忽略导演为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
解决方案返回NULL导向器并且不会获取标题。这个任务很简单,没有标题或没有导演,但是当他们都需要时,它更加棘手 – 2012-04-11 06:39:10
不是真的:)我添加了电影标题并删除了空导演(我不确定是否忽略导演为空的电影意味着将它们从结果中删除,以防万一,我做到了) – 2012-04-11 06:43:29
我找到了一个类似的解决方案,但它为所有电影提供了多个导演。答案显然需要每部电影最多一名导演(星级) – 2012-04-11 06:46:34