Ich habe eine bestehende MySQL-Tabelle mit Daten geladen (TblParts)Mysql Abfrage-Update Mit Bedingungen
Code Stock Price Location id
1 10 1000 Global 1
2 5 1500 Office 2
3 2 500 Global 3
4 1 100 Global 4
Ich habe eine zweite Tabelle mit neuen Informationen (TblNewParts)
Code Stock Price Location id
1 30 2000 Global 1
2 5 1000 Global 2
3 10 5000 Global 3
4 30 200 Global 4
5 40 500 Global 5
ich brauche TblParts zu aktualisieren mit TblPartsNeue Daten
wenn Code vorhanden ist, und Standort = global dann Bestand und Preis aktualisieren, wenn Code vorhanden ist, aber Standort <> Global dann Datensatz mit gleichem Code einfügen an d Distinct Ort, wenn Code nicht dann Exist hinzufügen es
Die Ausgabe von TblParts Must Be:
Code Stock Price Location
1 30 2000 Global
2 5 1500 Office
3 10 5000 Global
4 30 200 Global
5 40 500 Global
Was haben Sie versucht? – Strawberry
Was ist deine Frage? Hast du es schon probiert? – Dominik
Weil MySql keinen MERGE-Befehl hat, müssen Sie eine INSERT- und eine UPDATE-Abfrage schreiben. –