mysql 中 update set 的用法

用法:

UPDATE A, B SET A1 = B1, A2 = B2, A3 = B3 WHERE A.ID = B.ID

以两层select嵌套为例:

UPDATE supplier c,(
	SELECT
		supplier_id,
		sum( acc ) e
	FROM
		(
		SELECT
			a.purchase_no,
			a.STATUS,
			b.buy_price * b.num acc,
			b.supplier_id 
		FROM
			purchase a
			INNER JOIN purchase_detail b ON a.purchase_no = b.purchase_no 
		) result 
	WHERE
		STATUS = 1 
	GROUP BY
		supplier_id 
	) d 
SET c.total = d.e

你可能感兴趣的:(后端,mysql)