简体   繁体   English

MySQL尝试从其他两个表的列创建一个表

[英]MySql Try to create a table from columns from two other tables

I am trying to created a table from a few columns from two other tables. 我试图从其他两个表的几列中创建一个表。 I want this table to get data from the other two tables. 我希望该表从其他两个表中获取数据。 This is what I have so far 这就是我到目前为止

insert into crm_customer_coupon (barcode, customer_id,customer_name, coupon_name, number_of_times_used, product_sku)
select barcode, name, sku
From crm_coupons
Inner left Join crm_customer_extra_information where customer_id = 88

This is one of the tables rm_coupons set up 这是rm_coupons设置的表之一

id: Barcode: Name : Description: Type : Amount : sku 

This is the table rm_customer_extra_information 这是表rm_customer_extra_information

id : name: customer_id : ect...

and this is the table I want to put them into 这是我要放入的桌子

 barcode: customer_id : customer_name: coupon_name: product_sku

How do I go about combining them together, also how are they linked so I can get information from the other tables via a endpoint in spring later on. 如何将它们组合在一起,以及如何链接它们,以便稍后在春季通过端点从其他表中获取信息。 Thank you for any help with this 谢谢你的帮助

Try this: 尝试这个:

insert into crm_customer_coupon (barcode,name,sku)
select crm_coupons.barcode, crm_customer_extra_information.coupon_name, crm_coupons.sku
from crm_coupons
left Join crm_customer_extra_information on crm_coupons.id=crm_customer_extra_information.id
where customer_id = 88 

You forgot to mention you join field (i guess it's id), also you didn't mention which name field you want to insert, i put coupon_name, you can change the filed name in the subquery select. 您忘记提及您的联接字段(我想这是id),也没有提及要插入的名称字段,我输入coupon_name,可以在选择的子查询中更改字段名称。

It's easy: 这很容易:

   CREATE TABLE new_table 
      SELECT barcode, name,sku 
      FROM crm_coupons 
      // your code here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM