1. 程式人生 > >MySql 批量更新語法

MySql 批量更新語法

舉例 rom info round ber ner from sql數據庫 yam

mysql數據庫在批量更新某表的字段時,語法如下:

UPDATE A AS a
INNER JOIN (
SELECT
*
FROM
A
WHERE
....
) AS b ON a.order_id = b.order_id
SET a.pay_status = 2 ,a.abnormal = 4;

舉例

UPDATE Yamibuy_Master.xysc_order_info AS oi
INNER JOIN (
SELECT
order_id,order_sn,pay_status,abnormal
FROM
Yamibuy_Master.xysc_order_info
WHERE
abnormal = !4
AND order_status = 1
AND shipping_status = 0
AND pay_status = 0
AND warehouse_number = 002
) AS A ON oi.order_id = A.order_id
SET oi.pay_status = 2 , oi.abnormal = 4;

MySql 批量更新語法