日期:2014-05-18  浏览次数:20502 次

求SQL 2个表联合查询结果更新到第3表语句,速度结贴
有一个连接语句:select   T1.B,T2.D,T1.C,T1.D,T1.E,T1.F   from   1   as   T1   left   join   2   as   T2   on   T1.B=T2.G

我要把这个语句的结果更新到第3个表中,请高手给个方法
先谢了

------解决方案--------------------
update t3
set f1=t.d,f2=t.c,f3=t.d1,f4=t.ef5=t.f
from 3 as t3,(
select T1.B,T2.D,T1.C,T1.D as d1,T1.E,T1.F from 1 as T1 left join 2 as T2 on T1.B=T2.G
) as t
where t3.b=t.b


------解决方案--------------------
-- 如下.

update a
set -- 更新字段
from [3] a join (select T1.B,T2.D,T1.C,T1.D,T1.E,T1.F
from [1] as T1
left join [2] as T2
on T1.B=T2.G) b
on a.Id=b.Id -- 关联字段
Go
------解决方案--------------------
update 第三表
set 字段 = t.某个字段
from 第三表,t
(
select T1.B,T2.D,T1.C,T1.D,T1.E,T1.F from 1 as T1 left join 2 as T2 on T1.B=T2.G
) t
where 第三表.关键字 = t.关键字
------解决方案--------------------
这么麻烦干吗?
直接做视图就可以了。视图不就相当于第三个表了。