插入引用另一个表的值

插入引用另一个表的值,第1张

插入引用另一个表的值

我建议

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;

这使得错字导致错误价格的可能性大大降低。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5144163.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存