sql不支持直接修改查询结果,所以要修改的字段属于哪个表,就update那个表,where主键相等就可以了
mysql update的where条件不支持直接in子查询的结果集,所以子查询外要嵌套一层查询并指定别名
UPDATE
sm_free_member sfm
SET
sfm.order_id =
(SELECT
MAX(order_id)
FROM
sm_order so
WHERE so.member_id = sfm.member_id
AND package_id = 10
AND STATUS = 2)
WHERE sfm.free_member_id IN
(SELECT
temp.free_member_id
FROM
(SELECT
sfm.free_member_id
FROM
sm_free_member sfm,
sm_member sm
WHERE sfm.free_recom_id = 40
AND sfm.member_id = sm.member_id
AND (sm.type = 4
OR sm.type = 5)) AS temp)
mysql update的where条件不支持直接in子查询的结果集,所以子查询外要嵌套一层查询并指定别名
UPDATE
sm_free_member sfm
SET
sfm.order_id =
(SELECT
MAX(order_id)
FROM
sm_order so
WHERE so.member_id = sfm.member_id
AND package_id = 10
AND STATUS = 2)
WHERE sfm.free_member_id IN
(SELECT
temp.free_member_id
FROM
(SELECT
sfm.free_member_id
FROM
sm_free_member sfm,
sm_member sm
WHERE sfm.free_recom_id = 40
AND sfm.member_id = sm.member_id
AND (sm.type = 4
OR sm.type = 5)) AS temp)