我有一个列调用isDifFromother,它保持1或2(默认设置为0)。 当我更新一行时,如果isDifFromother值为0,我想设置2。 如果它有1我想保持原样。
如何在更新查询中检查该条件。
这是我的查询......,
UPDATE `customer` SET `name`='" + name + "', `isPackage`='" + packageID + "', `billing_ID`='" + biling_ID + "', `isDifFromother`=IF customer.isDifFromother = '1' THEN '2' END IF WHERE `id`='" + cusID + "';
但它嵌入了错误。
答案 0 :(得分:1)
if语句不正确,应该是
UPDATE `customer` SET `name`='" + name + "', `isPackage`='" + packageID + "', `billing_ID`='" + biling_ID + "', `isDifFromother`=IF(customer.isDifFromother = '0','2',customer.isDifFromother) WHERE `id`='" + cusID + "';
以下条件
`isDifFromother`=IF(customer.isDifFromother = '0','2',customer.isDifFromother)
如果其他0保持不变,则设置isDifFromother = 2.