SQL

Posted 长风破浪会有时

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL相关的知识,希望对你有一定的参考价值。

--查询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

以上是关于SQL的主要内容,如果未能解决你的问题,请参考以下文章

sql [sql技巧]一些sql技巧#sql

sql 2008 r2 在sql 2008上兼容么

SQL基础

有大神知道,sql server 中如何批量执行sql语句吗?

pl sql developer怎么执行sql

pl sql developer怎么执行sql