UPDATE goods_copy1 SET supplier_id = temp.supplier_id FROM goods_copy1 g1 INNER JOIN ( SELECT gpd.file_id, gpd.goods_id, im.supplier_id, g.supplier_id supplier_id2 FROM import_file im LEFT JOIN `goods_ppt_details` gpd ON gpd.file_id = im.file_id LEFT JOIN goods_copy1 g ON gpd.goods_id = g.goods_id WHERE gpd.tenant_id = 174 AND g.is_delete = '2' AND im.supplier_id != 0 AND g.supplier_id = 0 GROUP BY gpd.goods_id ) temp ON temp.goods_id = g1.goods_id这个执行不成功是什么问题
时间: 2024-01-16 08:05:28 浏览: 134
matlab.rar_GPD_GPD matlab_matlab GPD
这个 SQL 语句的问题可能是在 `UPDATE` 子句中没有指定要更新的表别名。你可以尝试以下修改:
```
UPDATE goods_copy1 g1
SET g1.supplier_id = temp.supplier_id
FROM (
SELECT gpd.goods_id, im.supplier_id
FROM import_file im
LEFT JOIN goods_ppt_details gpd ON gpd.file_id = im.file_id
LEFT JOIN goods_copy1 g ON gpd.goods_id = g.goods_id
WHERE gpd.tenant_id = 174 AND g.is_delete = '2' AND im.supplier_id != 0 AND g.supplier_id = 0
GROUP BY gpd.goods_id
) temp
WHERE temp.goods_id = g1.goods_id;
```
这里使用了别名 `g1` 指定要更新的表,同时将子查询的结果用作临时表来更新 `goods_copy1` 表。
阅读全文