22,209
社区成员
发帖
与我相关
我的任务
分享
--测试数据
if not object_id(N'Tempdb..#T') is null
drop table #T
Go
Create table #T([PTypeId] int,[UnitID] int,[PRTypeId] int,[Price] decimal(18,7))
Insert #T
select 100001,0,2,10 union all
select 100001,0,101,52 union all
select 100001,0,102,52 union all
select 100002,0,2,10 union all
select 100002,0,101,60 union all
select 100002,0,102,60 union all
select 300001,0,2,10 union all
select 300001,0,4,0.5 union all
select 300001,0,101,110 union all
select 300001,0,102,110 union all
select 300002,0,2,10 union all
select 300002,0,4,0.2 union all
select 300002,0,101,110 union all
select 300002,0,102,110
Go
--测试数据结束
UPDATE
c
SET
Price = a.Price + b.Price
FROM
#T a,
#T b,
#T c
WHERE
c.PTypeId LIKE '3%'
AND c.PRTypeId = 2
AND c.PTypeId = a.PTypeId
AND c.PTypeId = b.PTypeId
AND a.PRTypeId = 101
AND b.PRTypeId = 4;