我有一个程序,使用这2个参数向PHP发送2个字符串($ lic为许可证,$ hwid为hardwareid),我想更新“ hardwareid1,hardwareid2或hardwareid3”列(每个列的值均为NULL)登录),但我不想用相同的值填充2列(例如hardwareid1和hardwareid2)!因此,如果来自$ hwid的值已经存在于这三列之一中,则不需要更新。
UPDATE license
SET hardwareID3 = CASE WHEN hardwareID1 IS NOT NULL AND
hardwareID2 IS NOT NULL AND
hardwareID3 IS NULL
THEN '$hwid'
ELSE hardwareID3 END,
hardwareID2 = CASE WHEN hardwareID1 IS NOT NULL AND
hardwareID2 IS NULL
THEN '$hwid'
ELSE hardwareID2 END,
hardwareID1 = CASE WHEN hardwareID1 IS NULL
THEN '$hwid'
ELSE hardwareID1 END
WHERE code = '$lic'
解:
AND '$hwid' NOT IN (COALESCE(hardwareID1,hardwareID2,hardwareID3, 0))
最佳答案
即使设置了id3,您的代码也会更新hardwareId2和hardwareId1。不知道您想到达那里。
看一下COALESCE()
MySQL函数,该函数用于构建满足您需求的更复杂的语句:)