SQL Server 按月统计订单量

Use Basket

select convert(varchar(7),Orderdate,120) as YearMonth
,OrderID
,TotalCost
into #a
from Basket.dbo.BaseOrderTracker(nolock)
where OrderDate >=‘2013-07-01‘
and OrderDate <=‘2014-07-31‘
and OrderTypeID = 15
and OESourceID = 2
and StageID= 10400



select * from #a

select YearMonth,
COUNT(distinct OrderID),
SUM(TotalCost)
from #a (nolock)
group by YearMonth

drop table #a

  

SQL Server 按月统计订单量

上一篇:Oracle 查询字段在什么表


下一篇:00--C++牛人的博客