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

 

posted @ 2014-10-16 16:42  MonkeyFather  阅读(793)  评论(0编辑  收藏  举报