gpt4 book ai didi

mysql - 更新集,匹配单个列,单个查询中不同 ID 的多个值

转载 作者:行者123 更新时间:2023-11-29 02:41:12 32 4
gpt4 key购买 nike

我该怎么做:

UPDATE `TEST_TABLE` SET `C1` = 'VALUE_FOR_ID1' WHERE `ID` = 1;
UPDATE `TEST_TABLE` SET `C1` = 'VALUE_FOR_ID2' WHERE `ID` = 2;
UPDATE `TEST_TABLE` SET `C1` = 'VALUE_FOR_ID3' WHERE `ID` = 3;

使用具有匹配项的单个查询(类似这样):

UPDATE `TEST_TABLE` SET `C1` = ('VALUE_FOR_ID1','VALUE_FOR_ID2','VALUE_FOR_ID3') WHERE `ID` IN (1,2,3);

最佳答案

你应该能够使用CASE来做到这一点:

UPDATE  TEST_TABLE SET C1 =  
CASE
WHEN ID = 1 THEN 'VALUE_FOR_ID1'
WHEN ID = 2 THEN 'VALUE_FOR_ID2'
WHEN ID = 3 THEN 'VALUE_FOR_ID3'
END
WHERE ID IN (1,2,3)

关于mysql - 更新集,匹配单个列,单个查询中不同 ID 的多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51612615/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com