日期:2014-05-18  浏览次数:20626 次

这样的sql语句 更用update更新吗?
sql 代码
SQL code

select SUM(buyNumber) as zongshu,offer_id 
from dbo.crm_customer_offer_detail 
where offer_id in(select offer_id from dbo.crm_customer_offer) group by offer_id



我要把查询出的值 更新到 领一张表
假如 另一张表 有两列,一列 是要更新字段, 另一个是和 查询出的 offer_id值的关联字段(算是条件),这样的update 怎么写呢

求解 。。。先谢谢啦

------解决方案--------------------
SQL code
update tb
set value=t.zongshu
from
(select SUM(buyNumber) as zongshu,offer_id 
from dbo.crm_customer_offer_detail 
where offer_id in(select offer_id from dbo.crm_customer_offer) group by offer_id
) t
where tb.offer_id=t.offer_id