问题描述
我有三张桌子
1.line2
列是
line_id,gate_id_fk,line_name,area_id,类别(gate_id_fk是唯一的)
2.工作表2
列是
gate_id,类别,area_id,区域,年份(同一个gate_id是唯一的)
3.line3
line_id,gate_id_fk,line_name,area_id,类别,区域(gate_id_fk是唯一的)
现在我需要更新line2表,而我需要在line2表中更新的列是area_id,sheet2表和line3表中的类别
这些表的条件是
假设
line2(l2-Alias)
sheet2 B-Alias
line3 l3-Alias
第一个条件来自
的数据line3 l3是
其中L2.LINE_ID = L3.LINE_ID和L2.GATE_ID_FK为空)
和
第二个条件来自sheet2 b的数据
其中L2.GATE_ID_FK = B.GATE_ID);
我的问题是如何从两个表一起更新line2表中的area_id,category列
SQL查询或存储的proc plz.
Hi,
i have three tables
1.line2
columns are
line_id, gate_id_fk, line_name, area_id, category(gate_id_fk is unique)
2. sheet 2
columns are
gate_id, category, area_id, area, year (same gate_id is unique)
3.line3
line_id, gate_id_fk, line_name, area_id, category, area(gate_id_fk is unique)
now i need to update line2 table and the columns which i need to update in line2 table are area_id, category from sheet2 table and line3 table
condition for those tables are
suppose
line2 (l2-Alias)
sheet2 B-Alias
line3 l3-Alias
1st where condition for data which is coming from
line3 l3 is
where L2.LINE_ID= L3.LINE_ID and L2.GATE_ID_FK is null)
and
2nd where condition for data which coming from sheet2 b
where L2.GATE_ID_FK= B.GATE_ID);
my question is how to update area_id, category columns in line2 table from both the tables together
Sql query or Stored proc plz.
推荐答案
<br />
<br />
UPDATE L2<br />
SET L2.AreaID = S2.AreaID, <br />
L2.Category = L3.Category<br />
FROM Line2 L2<br />
INNER JOIN Sheet2 S2 ON L2.gateID = S2.gateID<br />
INNER JOIN Line3 L3 ON L3.gateID = S2.gateID<br />
<br />
如果您认为我对问题的理解不正确,请告诉我.
-Nayan
编码是尘世间的天堂
Please let me know if you think that I am not understanding the question properly.
-Nayan
Coding is an earthly heaven
这篇关于如何从另外2个其他表更新1个表中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!