search

Home  >  Q&A  >  body text

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?

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?

为情所困为情所困2749 days ago435

reply all(1)I'll reply

  • 迷茫

    迷茫2017-05-16 13:02:43

    Solved

    UPDATE `item` SET `item`.`sales` = IFNULL(`item`.`sales`, 0)+2 WHERE `item`.`id` = 2;

    reply
    0
  • Cancelreply