27,579
社区成员
发帖
与我相关
我的任务
分享
update TableA
set Result = ISNULL
(
(select t.AllCount from
(
select
P.TID,sum(P.Col1 * P.Col2) as AllCount
from
TableP P
where
P.X > 0
AND P.XX = 0
AND P.XXX = 1
AND P.XXX <> 23
group by P.TID
)
t
where t.TID = TableA.TID
)
,0)
where TID > 0
update TableA set result=t.AllCount
from TableA a,
(
select
P.TID,sum(P.Col1 * P.Col2) as AllCount
from
TableP P
where
P.X > 0
AND P.XX = 0
AND P.XXX = 1
AND P.XXX <> 23
group by P.TID
)t
where a.tid=t.tid and a.tid>0
UPDATE A
SET Result=ISNULL(T.Result,0)
FROM
TableA A JOIN
(
SELECT
A.TID,SUM(B.Col1 * B.Col2)Result
FROM
TableA A
LEFT JOIN TableP B ON A.TID=B.TID
GROUP BY
A.TID
)T ON A.TID=T.TID
WHERE
A.Result IS NULL