Mysql export sql
<code> 订单表trade字段:stock_num 已使用库存数字段:num 商品总数字段:num_iid 商品id</code>
<code> 商品表goods字段:total_stock_num 总库存数字段:num_iid 商品id</code>
Requirements to achieve:
Automatically reduce the number of total_stock_num, then set it to stock_num, and update the value of total_stock_num at the same time
Note:
1. stock_num may already have a value, where to reduce When adding the original value, it is required that stock_num<=num
2. total_stock_num may be 0, may be less than num (then subtract as much as you want), or may be greater than num (this can be subtracted directly)
I don’t have any coins, what should I do? Can anyone help me with the answer? Thank you
Since there are thousands of orders to be shipped out in batches, what I currently think of is to query and process them in the program, but this will require a lot of SQL to be executed
<code> 例子1:stock_num=2 num=5 total_stock_num=100出库后:stock_num=5 num=5 total_stock_num=97</code>
<code> 例子2:stock_num=0 num=5 total_stock_num=100出库后:stock_num=5 num=5 total_stock_num=95</code>
<code> 例子3:stock_num=2 num=5 total_stock_num=2出库后:stock_num=4 num=5 total_stock_num=0</code>
Use MYSQL -uroot -p123