回答

收藏

插入引用另一个表的值

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

我创建了以下简单的代码datamodel:! L3 K" y2 A8 a
  v, ?& C- ?9 J; V+ r) B8 j. {* V
我使用以下代码insert statements来插入值:# X) V# Q- C+ L2 o5 T
1)餐桌 产品    :
" X$ l+ G8 a! A6 L/ D: gINSERT INTO test.products(ProductName,Price)VALUES (&quotroduct A","99,99"),(&quotroduct B","49,95"),(&quotroduct C","5,95");2)表格 顺序    :
. S6 v/ k: h7 v! VINSERT INTO test.orders(Customer)VALUES ("Customer A"),("Customer B"),("Customer B");到目前为止,所有这些工作都很正常。
, |/ h( n( I! I$ M6 H$ Y) l6 a但是,现在我也想table中插入值Products_per_Order。
- ]: X8 _2 E% X! a+ F! [如您datamodel在Products_per_Order表格中看到的列包含Price。我想插入这个专栏的参考价格 ID4 I6 Y  L  u5 r6 W6 k/ c, g
列Products_idProducts。因此,我尝试使用以下方法,insert statement但到目前为止还没有正常工作:) j6 N2 R! Z# N2 D* ?  h: ~
INSERT 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");你有解决这个问题的想法吗?3 o+ G: L% O8 ~& u6 _" V' Z. y+ d
                                                                3 n" L$ F; y; {7 ?3 c, v$ B) F) I
    解决方案:

本帖子中包含更多资源

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

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

本版积分规则