如何编写带多条件的UPDATE语句实现GearLevel与BankMoney联动更新?
Fixing Your Multi-Condition UPDATE Query
Hey there! I see where the issue is with your test query—you forgot to add a WHERE clause to target only the specific row you want, which is why it was modifying every row in the table. Let's get that sorted out.
The Correct Query
To update only the row that meets all three of your conditions (matching UID, BankMoney = 25000000, and GearLevel = 15) and perform both value changes at once, use this query:
UPDATE PlayerInfo SET GearLevel = GearLevel + 1, BankMoney = BankMoney - 15000000 WHERE UID = "76561198008596823" AND BankMoney = 25000000 AND GearLevel = 15;
How It Works
- The
WHEREclause filters down to exactly the row you care about—no more accidental updates to other players' data. - The
SETclause handles both updates in one go: incrementingGearLevelby 1 and subtracting 15000000 fromBankMoney. Since we've already filtered the row with theWHEREconditions, we don't need aCASEstatement here (that was causing the broad update when noWHEREwas present).
Quick Safety Tip
Before running any UPDATE query, it's always smart to verify which rows will be affected first with a SELECT:
SELECT * FROM PlayerInfo WHERE UID = "76561198008596823" AND BankMoney = 25000000 AND GearLevel = 15;
This lets you confirm only the intended row is selected before making changes.
内容的提问来源于stack exchange,提问作者Mokey
相关产品推荐
相关产品推荐

