SQL Server 查询产品数量

use BASKET

select prd.PartID,
prd.Quantity,
prd.UnitRetailPrice,
prd.ItemDesc,
inf.orderdate
into #a
from Basket.dbo.BaseOrderItem  prd(nolock)
inner join Basket.dbo.BaseOrderTracker inf(nolock)
on(prd.OrderID=inf.OrderID)
where prd.SectionCode = '1'
and prd.UnitRetailPrice > 0
and prd.PartType = '1'
and inf.OrderDate >='2014-08-01'
and inf.OrderDate <='2014-09-30'

select * from #a

select PartID,
SUM(Quantity) as Quantity
into #b
from #a
where OrderDate >='2014-08-01'
and OrderDate <='2014-08-31'
group by PartID

select PartID,
SUM(Quantity) as Quantity
into #c
from #a
where OrderDate >='2014-09-01'
and OrderDate <='2014-09-30'
group by PartID

select * from #c
原文地址:https://www.cnblogs.com/monkeyfather/p/4029162.html