我有一个程序,使用这两个参数向 PHP 发送 2 个字符串(许可证为 $lic,hardwareid 为 $hwid),我想更新列“hardwareid1、hardwareid2 或 hardwareid3”(其中每个值为 NULL登录),但我不想用相同的值填充 2 列(例如 hardwareid1 和 hardwareid2)!因此,如果 $hwid 的值已经存在于这 3 列之一中,则不需要更新。
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))