Ich möchte eine Ansicht von 2 Tabellen mit einer Art von bedingten Join erstellen (Entschuldigung meine Ignoranz, wie ich SQL-Codierung neu bin!). Die beiden Tabellen sind wie folgt:Ansicht erstellen mit Join-Bedingungen
TABLE1
Store | Product | MAC Price
S001 | 123 | 15.00
S001 | 456 | 17.50
S002 | 123 | 16.00
S002 | 456 | 17.50
S002 | 789 | 20.00
TABLE2:
Store | Product | SELL Price
S001 | 123 | 25.00
S001 | 456 | 27.50
S002 | 123 | 26.00
SNAT | 123 | 35.00
SNAT | 456 | 40.00
Wo ich mit der Syntax habe Schwierigkeiten ist, dass TABLE2 entweder einen Preis auf Filialebene hat (z. B. S001) oder auf nationaler Ebene (z. B. SNAT) oder gar kein Preis.
Erforderlich Ausgabe anzeigen:
Store | Product | MAC Price | Sell Price
S001 | 123 | 15.00 | 25.00
S001 | 456 | 17.50 | 25.00
S002 | 123 | 16.00 | 26.00
S002 | 456 | 17.50 | 40.00 (no Store specifc, therefore SNAT)
S002 | 789 | 20.00 | 0.00 (no Store specifc or SNAT)
Mein aktueller Code wie unten aussieht ... Ich weiß nur nicht, wo/wie die Regeln für „wenn kein Speicher bestimmten Preis hinzufügen, SNAT verwenden, sonst 0,00" ...
create view SCH.Z_MAC_PRICE as
select SCH.table1.store, SCH.table1.product, SCH.table1.mac,
SCH.table2.sell
from SCH.table1 left outer join
SCH.table2
on SCH.table1.store = SCH.table2.store and
SCH.table1.product = SCH.table2.product
Danke für die schnelle Antwort! Das hat den Trick gemacht :) – Anton