2017-10-26 12 views
0

私はムービーをレビューするためのデータベースを作成していましたが、LEFT OUTER JOINを完了しようとしましたが、特定の批評家によって再検討された。私は行を互いに乗算するためにクロス結合を使用しなければなりませんでしたが、LEFT OUTER JOINからの結果を単独で取得する必要があります。ERモデルがLEFT OUTER JOINでMySQLでNULL値を生成しない

mysql> select * 
-> from F; 
+------------+--------------------------------+-------------+---------------- -----+-----------+ 
| FilmNumber | FilmName      | OpeningDate | TopBilledActor  | Genre  | 
+------------+--------------------------------+-------------+---------------- -----+-----------+ 
| F1   | Transformers: The Last Knight | 6/21/2017 | Mark Wahlberg  | Action | 
| F2   | Cars 3       | 6/16/2017 | Owen Wilson   | Animation | 
| F3   | Wonder Woman     | 6/2/2017 | Gal Gadot   | Action | 
| F4   | All Eyez on Me     | 6/16/2017 | Demetrius Shipp Jr. | Biography | 
| F5   | The Mummy      | 6/9/2017 | Tom Cruise   | Action | 
| F6   | Rough Night     | 6/16/2017 | Scarlett Johansson | Comedy | 
| F7   | Guardians of the Galaxy Vol. 2 | 5/5/2017 | Chris Pratt   | Action | 
| F8   | Men Tell No Tales    | 5/26/2017 | Johnny Depp   | Action | 
| F9   | 47 Meters Down     | 6/16/2017 | Mandy Moore   | Adventure | 
| F10  | Captain Underpants    | 6/2/2017 | Kevin Hart   | Animation | 
+------------+--------------------------------+-------------+---------------- -----+-----------+ 
10 rows in set (0.00 sec) 

mysql> select * 
-> from C; 
+------------------+----------------------+-----------------+ 
| CriticSiteNumber | CriticSiteName  | CriticName  | 
+------------------+----------------------+-----------------+ 
| C1    | The New York Times | Neil Genzlinger | 
| C2    | Variety    | Owen Gleiberman | 
| C3    | Variety    | Andrew Barker | 
| C4    | IndieWire   | Judy Dry  | 
| C5    | IndieWire   | Eric Kohn  | 
| C6    | Paste Magazine  | Tim Grierson | 
| C7    | We Got This Covered | Matt Donato  | 
| C8    | Entertainment Weekly | Chris Nashawty | 
+------------------+----------------------+-----------------+ 
8 rows in set (0.00 sec) 
mysql> select * 
    -> from FC; 
+------------+------------------+--------------+ 
| FilmNumber | CriticSiteNumber | OverallScore | 
+------------+------------------+--------------+ 
| F1   | C1    |   50 | 
| F1   | C2    |   60 | 
| F1   | C5    |   50 | 
| F1   | C6    |   20 | 
| F1   | C7    |   40 | 
| F1   | C8    |   58 | 
| F2   | C1    |   80 | 
| F2   | C2    |   70 | 
| F2   | C5    |   83 | 
| F2   | C6    |   50 | 
| F2   | C7    |   60 | 
| F3   | C1    |   80 | 
| F3   | C2    |   82 | 
| F3   | C3    |   78 | 
| F3   | C4    |   72 | 
| F3   | C6    |   81 | 
| F3   | C8    |   85 | 
| F4   | C1    |   20 | 
| F4   | C2    |   60 | 
| F4   | C4    |   58 | 
| F4   | C6    |   42 | 
| F5   | C2    |   50 | 
| F5   | C4    |   16 | 
| F5   | C6    |   52 | 
| F5   | C7    |   30 | 
| F5   | C8    |   67 | 
| F6   | C1    |   40 | 
| F6   | C2    |   70 | 
| F6   | C3    |   65 | 
| F6   | C5    |   83 | 
| F6   | C6    |   43 | 
| F6   | C7    |   70 | 
| F6   | C8    |   58 | 
| F7   | C2    |   70 | 
| F7   | C5    |   67 | 
| F7   | C6    |   80 | 
| F7   | C7    |   80 | 
| F7   | C8    |   67 | 
| F8   | C3    |   38 | 
| F8   | C4    |   51 | 
| F8   | C6    |   22 | 
| F8   | C7    |   58 | 
| F8   | C8    |   45 | 
| F9   | C1    |   55 | 
| F9   | C2    |   44 | 
| F9   | C4    |   50 | 
| F9   | C6    |   70 | 
| F9   | C7    |   60 | 
| F9   | C8    |   67 | 
| F10  | C1    |   69 | 
| F10  | C2    |   60 | 
| F10  | C4    |   55 | 
| F10  | C7    |   70 | 
| F10  | C8    |   83 | 
+------------+------------------+--------------+ 
54 rows in set (0.00 sec) 

mysql> 

これらは私のテーブルがあるので、あなたは映画が特定の批評家によってスコアが与えられていなかった多くの事例があることがわかりますが、私は私の教授によって示されるようにLEFT OUTERは、結合を実行する場合、これらは私の結果であります:

私が得ようとしている結果は、OverallScore列に、特定の評論家によって行われたレビューがなかったすべてのインスタンスに対してNULL値が存在する結果です。言い換えれば、クエリにCROSS JOINまたはNULLを使用することなく、合計80行(10枚の映画、8名の批評家)が見たいと思っています。

mysql> select F.FilmName, FC.CriticSiteNumber, FC.OverallScore 
    -> from F LEFT OUTER JOIN FC 
    -> on F.FilmNumber=FC.FilmNumber 
    -> order by FilmName; 
+--------------------------------+------------------+--------------+ 
| FilmName      | CriticSiteNumber | OverallScore | 
+--------------------------------+------------------+--------------+ 
| 47 Meters Down     | C1    |   55 | 
| 47 Meters Down     | C2    |   44 | 
| 47 Meters Down     | C4    |   50 | 
| 47 Meters Down     | C6    |   70 | 
| 47 Meters Down     | C7    |   60 | 
| 47 Meters Down     | C8    |   67 | 
| All Eyez on Me     | C1    |   20 | 
| All Eyez on Me     | C2    |   60 | 
| All Eyez on Me     | C4    |   58 | 
| All Eyez on Me     | C6    |   42 | 
| Captain Underpants    | C1    |   69 | 
| Captain Underpants    | C2    |   60 | 
| Captain Underpants    | C4    |   55 | 
| Captain Underpants    | C7    |   70 | 
| Captain Underpants    | C8    |   83 | 
| Cars 3       | C1    |   80 | 
| Cars 3       | C2    |   70 | 
| Cars 3       | C5    |   83 | 
| Cars 3       | C6    |   50 | 
| Cars 3       | C7    |   60 | 
| Guardians of the Galaxy Vol. 2 | C2    |   70 | 
| Guardians of the Galaxy Vol. 2 | C5    |   67 | 
| Guardians of the Galaxy Vol. 2 | C6    |   80 | 
| Guardians of the Galaxy Vol. 2 | C7    |   80 | 
| Guardians of the Galaxy Vol. 2 | C8    |   67 | 
| Men Tell No Tales    | C3    |   38 | 
| Men Tell No Tales    | C4    |   51 | 
| Men Tell No Tales    | C6    |   22 | 
| Men Tell No Tales    | C7    |   58 | 
| Men Tell No Tales    | C8    |   45 | 
| Rough Night     | C1    |   40 | 
| Rough Night     | C2    |   70 | 
| Rough Night     | C3    |   65 | 
| Rough Night     | C5    |   83 | 
| Rough Night     | C6    |   43 | 
| Rough Night     | C7    |   70 | 
| Rough Night     | C8    |   58 | 
| The Mummy      | C2    |   50 | 
| The Mummy      | C4    |   16 | 
| The Mummy      | C6    |   52 | 
| The Mummy      | C7    |   30 | 
| The Mummy      | C8    |   67 | 
| Transformers: The Last Knight | C1    |   50 | 
| Transformers: The Last Knight | C2    |   60 | 
| Transformers: The Last Knight | C5    |   50 | 
| Transformers: The Last Knight | C6    |   20 | 
| Transformers: The Last Knight | C7    |   40 | 
| Transformers: The Last Knight | C8    |   58 | 
| Wonder Woman     | C1    |   80 | 
| Wonder Woman     | C2    |   82 | 
| Wonder Woman     | C3    |   78 | 
| Wonder Woman     | C4    |   72 | 
| Wonder Woman     | C6    |   81 | 
| Wonder Woman     | C8    |   85 | 
+--------------------------------+------------------+--------------+ 
54 rows in set (0.00 sec) 
+0

「LEFT OUTER JOIN」はどこですか?クエリに間違った結果を与えるものはありません。 – mypetlion

+0

私の間違い私は間違ったクエリをコピーしました: – Justin

+0

正しいものが最後に投稿されました – Justin

答えて

0

問題は、クエリにCテーブルが含まれていないように見えます。したがって、FCテーブルのFテーブルにのみ参加しているため、クエリではNULLの値は取得されません。エンジンは結果にすべての批評家を含めることを基本的には望んでいないことを知りません。試してみてください:

mysql> select F.FilmName, C.CriticSiteNumber, FC.OverallScore 
-> from F LEFT OUTER JOIN FC 
-> on F.FilmNumber=FC.FilmNumber 
-> LEFT OUTER JOIN C 
-> ON C.CriticSiteNumber = FC.CriticSiteNumber 
-> order by FilmName; 
関連する問題