我想删除mysql中的一部分行。
我的行:1,2,3,4
我想做: 1,2,3
我该怎么做?
我知道可以用这段代码完成,但是有更好的方法吗?
UPDATE Table SET message = REPLACE(message, ",4", "") WHERE id = 1;
所以这将起作用。
UPDATE Table SET message = CASE
WHEN message LIKE '4,%'
THEN // enter code here to replace '4,' in message with ''
WHEN message LIKE '%,4,%'
THEN // enter code here to replace ',4,' in message with ','
WHEN message LIKE '%,4'
THEN // enter code here to replace ',4' in message with ''
ELSE // this means all other occurances of 4 like 14,41,44,etc do nothing here or skip this else condition
END;
为了安全起见,您需要在测试服务器中测试代码。
İf 你会替换,4 ,mysql 也会替换 ,40
您必须更改字符串
,1,2,3,4,
你必须替换,4,