回答

收藏

插入引用另一个表的值

技术问答 技术问答 270 人阅读 | 0 人回复 | 2023-09-12

我创建了以下简单的代码datamodel:
% s. R& i9 Q9 \% N1 E% p% `
( ?: N( x6 M# q) t; U1 G我使用以下代码insert statements来插入值:
7 ^' q5 t# k2 A1)餐桌 产品    :  t3 q" x5 J! ^5 M9 d; c$ P0 }, o) a/ @
INSERT INTO test.products(ProductName,Price)VALUES (&quotroduct A","99,99"),(&quotroduct B","49,95"),(&quotroduct C","5,95");2)表格 顺序    :# S4 x- V9 r! f# x8 D2 S. U3 |
INSERT INTO test.orders(Customer)VALUES ("Customer A"),("Customer B"),("Customer B");到目前为止,所有这些工作都很正常。
' u2 h6 T2 O" {4 H5 D/ z- M9 X4 Q但是,现在我也想table中插入值Products_per_Order。
1 ~1 ^( m2 F; G; |如您datamodel在Products_per_Order表格中看到的列包含Price。我想插入这个专栏的参考价格 ID% j# I$ V6 V5 k9 {
列Products_idProducts。因此,我尝试使用以下方法,insert statement但到目前为止还没有正常工作:
( N; g2 [: o/ ^9 d& `) FINSERT INTO test.products_per_order(Orders_idOrders,Products_idProducts,Price,Quantity)VALUES("1","1",(Select Price from test.products),"5"),("1","2",(Select Price from test.products),"4"),("2","1",(Select Price from test.products),"10"),("3","2",(Select Price from test.products),"3"),("3","3",(Select Price from test.products),"9");你有解决这个问题的想法吗?
, X; n" r% Q$ z                                                                9 K" T- W, y1 E
    解决方案:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则