日期:2014-05-17 浏览次数:20640 次
--更新
;with cte as(
select codeid as cid,sum(clicks) as csum from dbo.clicks
group by codeid
)
update dbo.BusCode set views=views+csum from cte where codeid=cid
update dbo.BusCode
set views=views+csum
from
(
select codeid,sum(clicks) as csum
from dbo.clicks
group by codeid
)t
where t.codeid= BusCode.codeid
UPDATE dbo.BusCode
SET dbo.BusCode.VIEWS=dbo.BusCode.VIEWS+b.clicks
FROM (
SELECT codeid,SUM(clicks)clicks
FROM dbo.Clicks
GROUP BY codeid)b
WHERE dbo.BusCode.codeid=b.codeid