[英]insert into a table based on condition in another
I have trying to build a table from a condition existing in another table. 我试图从另一个表中存在的条件构建表。 If the condition exists I want to pull data from a different table to populate the new table.
如果条件存在,我想从其他表中提取数据以填充新表。 Here is the SQL statements I am using, however it is populating the new table with the wrong data.
这是我正在使用的SQL语句,但是它使用错误的数据填充了新表。
INSERT INTO 2014TranstarPriceTnum (tran_no)
SELECT Tran_no
FROM Trans_Types_Updated
WHERE 2014TranstarPriceTtype.`tran_type`=Trans_Types_Updated.`Tran_Type`;
I am looking in 2014TranstarPriceTtype
for a Trans Type that exists for the and pull all the associated tran_no
's from Trans_Types_Updated
and populate 2014TranstarTnum
. 我期待在
2014TranstarPriceTtype
针对存在的一个跨类型和把所有相关的tran_no
从的Trans_Types_Updated
和填充2014TranstarTnum
。 However, my script resulted in the Tran_Type
populated into the tran_no field. 但是,我的脚本导致将
Tran_Type
填充到tran_no字段中。
2014TranstarPriceTtype
Tprice tran_type make core note Updated
650 125C BUICK 250 (P.H.B.) 2014-01-07
650 200C BUICK 250 (P.H.B.) 2014-01-07
850 2004R BUICK 350 (P.H.B.) 2014-01-07
650 350 Chev 250 (P.H.B.) 2014-01-07
Trans_Type_Updated Trans_Type_Updated
Tran_No Tran_Type Make Eng_size
T1014AA 125C BUICK 2.5
T1006AA 125C BUICK 2.5
T1363AA 2004R BUICK 5.0
T1365AA 2004R BUICK 5.0
T1310AA 200C BUICK 3.8 (231)
T1318AA 200C BUICK 5.0
T1427CA 350C CHEVROLET 5.0
T1427AA 350C CHEVROLET 5.0
Results in 2014TranstarPriceTnum
2014TranstarPriceTnum
结果2014TranstarPriceTnum
tran_no Tprice tran_type make eng_size core_tote note updated
125C \N \N \N \N \N \N \N
200C \N \N \N \N \N \N \N
2004R \N \N \N \N \N \N \N
350C \N \N \N \N \N \N \N
I would appreciated any help. 我将不胜感激。
Thanks, 谢谢,
Tony Cripps 托尼·克里普斯
Hmm, not that clear, but I think you want something like that (not sure of your table names, you've got different versions). 嗯,不是很清楚,但是我想您想要这样的东西(不确定您的表名,您使用的版本不同)。
INSERT INTO 2014TranstarPriceTnum (tran_no)
SELECT ttu.Tran_no
FROM Trans_Type_Updated ttu
INNER JOIN 2014TranstarPriceTtype tpt on tpt.tran_type = ttu.tran_type
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.