Home  >  Article  >  Database  >  Database export sql - Please tell me how to write mysql batch database export statement. Can it be implemented in one sentence?

Database export sql - Please tell me how to write mysql batch database export statement. Can it be implemented in one sentence?

WBOY
WBOYOriginal
2016-12-05 13:27:351610browse

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>

Reply content:

Use MYSQL -uroot -p123

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn