您的位置:首页 > 博客中心 > 数据库 >

SQL Server 按月统计订单量

时间:2022-03-13 23:09

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

  

热门排行

今日推荐

热门手游