取指定时间下订单的人数,按时间列表

create table #ttt
(
id int primary key
)

insert into #ttt
select 0 union
select 1 union
select 2 union
select 3 union
select 4 union
select 5 union
select 6 union
select 7

insert into #ttt select 0

select distinct dateAdd(day,id,'20161201') as 日期,count(dateAdd(day,id,'20161201')) over(partition by dateAdd(day,id,'20161201')) from #ttt left join [QPTreasureDB].[dbo].[OnLineOrder] o on
datediff(day,dateAdd(day,id,'20161201'),o.ApplyDate)=0
where dateAdd(day,id,'20161201') between '20161201' and '20161205' order by dateAdd(day,id,'20161201') desc


select convert(varchar(10),ApplyDate,120),count(1) from [QPTreasureDB].[dbo].[OnLineOrder] where applyDate between '2016-12-01 00:00:00' and '2016-12-05 23:59:59'
group by convert(varchar(10),ApplyDate,120) order by convert(varchar(10),ApplyDate,120) desc

 

posted @ 2016-12-21 17:38  唔愛吃蘋果  阅读(162)  评论(0编辑  收藏  举报