Last active
December 22, 2015 15:29
-
-
Save rangercyh/6493075 to your computer and use it in GitHub Desktop.
SQL更新列数据,如果UNIQUE约束的key有重复的,则执行更新,否则插入一条新的
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO test_tong VALUES | |
("aaa", 9), ("asdf", 9), ("bbb", 9) | |
ON DUPLICATE KEY UPDATE | |
score = VALUES(score) | |
UPDATE test_tong SET | |
score = CASE tongname | |
WHEN "aaa" THEN 1 | |
WHEN "asdf" THEN 2 | |
WHEN "bbb" THEN 3 | |
END | |
WHERE tongname IN("aaa", "asdf", "bbb") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment