我有这个问题:
UPDATE orders SET tracking = '$trackingnumber', tracking_timestamp = NOW()
WHERE comment like '%$ordernumber%'
如果该字段的值为0000-00-00 00:00:00,是否可以更新tracking_timestamp?
答案 0 :(得分:2)
您可以使用CASE
UPDATE orders
SET tracking = '$trackingnumber',
tracking_timestamp = CASE
WHEN tracking_timestamp='0000-00-00 00:00:00'
THEN NOW()
ELSE tracking_timestamp
END
WHERE comment like '%$ordernumber%'
答案 1 :(得分:0)
使用此查询
UPDATE orders
SET tracking = '$trackingnumber',
tracking_timestamp = IF (tracking_timestamp='0000-00-00 00:00:00',NOW(),'0000-00-00 00:00:00')
WHERE COMMENT LIKE '%$ordernumber%'