Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 更新具有相同总和和分组依据的两列_Sql_Sql Server 2008 - Fatal编程技术网

Sql 更新具有相同总和和分组依据的两列

Sql 更新具有相同总和和分组依据的两列,sql,sql-server-2008,Sql,Sql Server 2008,我想用这个查询中的值更新,但它说的是错误。。。我正试图把它最小化 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 in

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

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
像这样试试

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
像这样试试

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

嗨,巴哈多,欢迎来到SO。用波斯语写你的名字绝对不是一个好主意,伙计,其他人可能读不懂你的名字。我不知道该怎么称呼他-@MahdiTahsildari我正要叫他“蛇”哈哈哈:)@Aniket他的英文名字是Bahadorbaradarant这是个好名字:-)谢谢@MahdiTahsildaricheck这个解决方案可能对你有用..嗨,Bahador,欢迎来到SO。用波斯语写你的名字绝对不是个好主意,伙计,其他人可能读不懂你的名字。我不知道该怎么称呼他-@MahdiTahsildari我正要叫他“蛇”哈哈哈:)@Aniket他的英文名字是Bahadorbaradarant这是个好名字:-)谢谢@MahdiTahsildaricheck这个解决方案可能对你有用。。