php - 如何写mysql当字段sales为null时设置为数字quantity,否则设置sales为原sales+quantity?
为情所困
为情所困 2017-05-16 13:00:43
0
1
413

item表里有个int类型的字段sales,如何使用sql更新销量sales,当字段sales为null时设置为数字quantity,否则设置sales为原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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!