Apache Hiveでは、左のデータからすべてのデータを保持し、可能な場合は右の表からデータを追加するために左結合したいテーブルが必要です。 これは2つのフィールド(material_idとlocation_id)に基づいているため、2つの結合を使用します。 これは、2つの伝統的な左で正常に動作しますが、加入:Hive/SQL - フォールバック付きの左結合
SELECT
a.*,
b.*
FROM a
INNER JOIN (some more complex select) b
ON a.material_id=b.material_id
AND a.location_id=b.location_id;
をLOCATION_IDデータベースは2つのだけ異なる値が含まれているため、1と2
私たちは今、「いいえがある場合はその要件を持っていると言いますこれは、material_idのみが結合可能であり、bテーブルのlocation_idの結合にmaterial_idとlocation_id(例えばmaterial_id = 100とlocation_id = 1)の正しい組み合わせがないことを意味します。 location_idの他の可能な値へのフォールバックまたはフォールバックmaterial_id = 001およびlocation_id = 2およびその逆。これは、location_idの場合のみである必要があります。
私たちはすでにCASEなどですべての可能な回答を見てきましたが、勝ってはいけません。
...
ON a.material_id=b.material_id AND a.location_id=
CASE WHEN a.location_id = b.location_id THEN b.location_id ELSE ...;
のようなセットアップは、我々は試してみましたかハイブクエリ言語で行う方法を本当に把握しませんでした。
ありがとうございました!たぶん誰かが賢明なアイデアを持っています。
Table a
| material_id | location_id | other_column_a |
| 100 | 1 | 45 |
| 101 | 1 | 45 |
| 103 | 1 | 45 |
| 103 | 2 | 45 |
Table b
| material_id | location_id | other_column_b |
| 100 | 1 | 66 |
| 102 | 1 | 76 |
| 103 | 2 | 88 |
Left - Join Table
| material_id | location_id | other_column_a | other_column_b
| 100 | 1 | 45 | 66
| 101 | 1 | 45 | NULL (mat. not in b)
| 103 | 1 | 45 | DEFAULT TO where location_id=2 (88)
| 103 | 2 | 45 | 88
PS:サブクエリONに動作しないhere存在等を述べたようにここ
は、いくつかのサンプルデータです。
サンプルデータを表示する必要があります。 – Andrew
ありがとうAndrew、わかりやすくするためにいくつかのサンプルデータを追加しました。 – alpcoder