码迷,mamicode.com
首页 > 数据库 > 详细

SQL Server 按月统计订单量

时间:2014-08-29 17:51:10      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:blog   os   ar   2014   div   log   on   c   sql   

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 按月统计订单量

标签:blog   os   ar   2014   div   log   on   c   sql   

原文地址:http://www.cnblogs.com/monkeyfather/p/3945352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!