1

我想用这个查询中的值进行更新,但它说的是错误……我正试图将它最小化。

update p
set a10=t.sumgc
from temp as p inner join 
(SELECT     SUM(gcsanad) as sumgc,good_gr
fROM         dbo.fgoodgroup 
WHERE     (flag = 2)
group by good_gr ) as t
on t.good_gr=p.a3
,
a11=t.sumgc
from temp as p inner join 
(SELECT     SUM(gcsanad) as sumgc,good_gr
fROM         dbo.fgoodgroup 
WHERE     (flag = 4) 
group by good_gr ) as t
on t.good_gr=p.a3
4

1 回答 1

1

试试这样

update p
set a10=t.sumgc
,
a11=t.sumgc1

from temp as p inner join 
(SELECT 
  (case when  flag = 2 then   SUM(gcsanad)  end) as sumgc,
  (case when  flag = 4 then   SUM(gcsanad)  end) as sumgc1
fROM         dbo.fgoodgroup 
group by good_gr ) as t
on t.good_gr=p.a3
于 2013-01-28T07:57:39.503 回答