私はwww.db-class.com演習を解決しています。遅れても質問はまだ興味深いです。私は余分なもので最後の仕事に遭遇し、解決策を理解することができません。以下のデータベース全体がherewww.db-class.comのSQLクエリ
質問obtaintedすることができ
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);
です::各取締役に対して
Q12を監督名を返し、次のように
SQL方式があります彼らが監督した映画のタイトル( )と一緒に、すべての映画の中で最も高い評価を受けたのは である。その評価のue。 ディレクタが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ディレクタを返し、タイトルを取得しません。タスクはタイトルなしで、または取締役がなくても簡単ですが、両方とも必要なときには、はるかにトリッキーです –
実際にはありません:)映画のタイトルを追加してヌルディレクターを削除しました( 'ディレクターがNULLの映画は無視する –
私は同様の解決策を見つけましたが、すべての映画に対して複数の監督を与えています。答えには明らかに映画1台につき1人の最大(星)が必要です –