22,210
社区成员
发帖
与我相关
我的任务
分享
--测试数据
if not object_id(N'Tempdb..#tabDIYTable785') is null
drop table #tabDIYTable785
Go
Create table #tabDIYTable785([a1] int,[b1] decimal(18,7),[c1] decimal(18,7))
Insert #tabDIYTable785
select 123,10.1,NULL
GO
if not object_id(N'Tempdb..#tabDIYTable1287') is null
drop table #tabDIYTable1287
Go
Create table #tabDIYTable1287([a1] int,[c1] decimal(18,7))
Insert #tabDIYTable1287
select 123,10.1 union all
select 123,15
Go
--测试数据结束
UPDATE #tabDIYTable785
SET c1 = t.c1
FROM ( SELECT a1 ,
SUM(c1) AS c1
FROM #tabDIYTable1287
GROUP BY a1
) t
WHERE t.a1 = #tabDIYTable785.a1
SELECT * FROM #tabDIYTable785