php - How to write mysql to set the field sales to numeric quantity when it is null, otherwise set sales to the original sales+quantity?
为情所困
为情所困 2017-05-16 13:00:43
0
1
468

There is an int type field sales in the item table. How to use SQL to update the sales volume? When the sales field is null, set it to the numerical quantity, otherwise set sales to the original sales+quantity?

为情所困
为情所困

reply all(1)
迷茫

Solved

UPDATE `item` SET `item`.`sales` = IFNULL(`item`.`sales`, 0)+2 WHERE `item`.`id` = 2;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template