[英]Insert using selecting column from other table
I have three tables as below我有如下三张表
I want to insert the column dep_typ in table 2 as selecting the column from table 1.我想在表 2 中插入列 dep_typ 作为从表 1 中选择列。
But the dep_typ
in table 2 has all 4 values as 'U' and whereas in table 1 it is three times 'U' and 1 time 'F'.但是表 2 中的
dep_typ
将所有 4 个值都设为“U”,而在表 1 中,它是“U”的三倍和“F”的 1 倍。 I want the result to be as same as table 1.我希望结果与表 1 相同。
The following will join the dep_type values from t1 with only the records from t2.以下将仅将来自 t1 的 dep_type 值与来自 t2 的记录连接起来。 Your data sample does not have any matching
ex_line
values common to t1 and t2.您的数据样本没有任何与 t1 和 t2 相同的匹配
ex_line
值。 Is this true of the entire dataset?整个数据集都是这样吗? It if isn't true for the entire dataset, then @OldProgrammer is right - the join will not return the exact number of records in t1.
如果整个数据集不正确,那么@OldProgrammer 是正确的 - 连接不会返回 t1 中的确切记录数。
SELECT
t1.position,
t1.ss_id,
t2.ex_line,
t1.dep_Typ,
t1.num
FROM
t1
INNER JOIN
t2
ON t1.position = t2.position
AND t1.ss_id = t2.ss_id
INNER JOIN
t3
ON t1.ss_id = t3.ss_id
AND t1.value = t3.value
AND t2.vech_num = t3.vech_num
;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.