标签:
--查询Positions中不存在,ProductAddCountTemp中存在,并且将ProductAddCountTemp中CustomerIdheProductId相同的的行,合并为一行
select CustomerId,CustomerName,ProductId,ProductName,SUM(Count)Count,SUM(Count*Price)Cost from
(
select * from ProductAddCountTemp AS Temp
where (select COUNT(1) as num from Positions where Positions.CustomerId=Temp.CustomerId AND Positions.ProductId=Temp.ProductId) = 0
) as newForm
group by CustomerId,CustomerName,ProductId,ProductName
--查询Posistion中不存在的,但ProductAddCountTemp中存在的
--select * from ProductAddCountTemp AS Temp
--where (select COUNT(1) as num from Positions where Positions.CustomerId=Temp.CustomerId AND Positions.ProductId=Temp.ProductId) = 0
--更新Positions,依据ProductAddCountTemp中的数据,在Positions中存在
--UPDATE Positions SET Count += Temp.TCount, Cost += Temp.Cost
--FROM
--Positions,
--(
-- SELECT CustomerId,ProductId,SUM(Count)TCount,SUM(Count*Price)Cost
-- FROM ProductAddCountTemp
-- GROUP BY CustomerId,ProductId
--) AS Temp
--WHERE Positions.CustomerId=Temp.CustomerId AND Positions.ProductId=Temp.ProductId
标签:
原文地址:http://www.cnblogs.com/lowy/p/5857081.html