TEL:150-0382-3679
新闻资讯 News Center
建站知识 / 公司动态
mssql指定时间段按日期分组,没有数据补0的解决办法
select convert(varchar,a.d,111) as [日期],
isnull(b.qty,0) as [销量]
  from 
(
---生成时间段内所有的天数
select dateadd(day,number,'2020-04-19') as d from master..spt_values 
where type='p' 
and number >=0 
and dateadd(day,number,'2020-04-19') between '2020-04-19' and dateadd(day,0,'2020-04-23')


) as a 
left join 
(
 ---按天汇总的销量数据
 select convert(varchar,addtime,111) as d,count(id) as qty from Visiting_Log group by  convert(varchar,addtime,111)
) as b 
 on  convert(varchar,a.d,111) = b.d 
一站式全网营销,您身边的网络营销顾问,为您一对一私人定制符合您实际需求的网络营销实施方案!
24小时咨询热线:
150-0382-3679