[英]insert into a table based on condition in another
我試圖從另一個表中存在的條件構建表。 如果條件存在,我想從其他表中提取數據以填充新表。 這是我正在使用的SQL語句,但是它使用錯誤的數據填充了新表。
INSERT INTO 2014TranstarPriceTnum (tran_no)
SELECT Tran_no
FROM Trans_Types_Updated
WHERE 2014TranstarPriceTtype.`tran_type`=Trans_Types_Updated.`Tran_Type`;
我期待在2014TranstarPriceTtype
針對存在的一個跨類型和把所有相關的tran_no
從的Trans_Types_Updated
和填充2014TranstarTnum
。 但是,我的腳本導致將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
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
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
我將不勝感激。
謝謝,
托尼·克里普斯
嗯,不是很清楚,但是我想您想要這樣的東西(不確定您的表名,您使用的版本不同)。
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.