-- 訂單詳情表增長商品主圖字段
ALTER TABLE t_ord_detail ADD COLUMN prod_img_path varchar(1000) COMMENT '商品主圖';圖片
-- 根據訂單詳情表商品ID關聯圖片表裏的主圖,把先有的主圖URL賦給訂單詳情表商品主圖字段
UPDATE t_ord_detail ordDetail INNER JOIN(SELECT * FROM (
SELECT detail.prod_id,pic.path from t_ord_detail detail INNER JOIN t_pd_picture pic ON detail.prod_id = pic.product_id
where pic.picture_pd_type = 0)subTemplate)newTemplate on ordDetail.prod_id = newTemplate.prod_id
SET ordDetail.prod_img_path = newTemplate.path;table
-- 替換prod_info裏面的picPath對應的值爲prod_img_path字段的值
UPDATE t_ord_detail SET prod_info = REPLACE(prod_info,SUBSTRING(
prod_info,
LOCATE('"picPath":', prod_info),
LOCATE(',"contacts":', prod_info) - LOCATE('"picPath":', prod_info)
),CONCAT('"picPath":"',prod_img_path,'"'));im
-- 訂單詳情表刪除商品主圖字段
alter table t_ord_detail drop column prod_img_path;img