update
A sp -- 主表
left join B cc on cc.id = sp.customer_commodity_id -- 替他表
left join C c on c.commodity_code = cc.commodity_code and c.status=3
left join D cp on cp.commodity_id = c.id and cp.is_deleted = 1 and cp.is_default=1 and cp.status=3
set sp.unit_code = cp.unit_code --更新值
where sp.unit_code is null and cp.unit_code is not null;
where 条件放在最后,不然报错!