作者:JohnBeanLee | 来源:互联网 | 2023-10-12 19:29
我建议insert . . . select
改用:
insert into test.products_per_order (Orders_idOrders, Products_idProducts, Price, Quantity)
select x.idOrder, x.idProduct, p.price, x.qty
from (select 1 as idOrder, 2 as idProduct, 5 as qty union all
select 1 as idOrder, 2 as idProduct, 4 as qty union all
. . . -- I've left these out so you can see the structure of the query
select 3 as idOrder, 3 as idProduct, 9 as qty
) x left join
test.products p
on p.idProducts = x.idProduct;
这使得错字导致错误价格的可能性大大降低。