【sql】SQL日期的自动补全填充

1,测试表
【sql】SQL日期的自动补全填充_第1张图片
2,SQL处理

select t1.chartTime,isnull(t2.countNum,0)errorCount,isnull(t3.countNum,0)warnConut,isnull(t4.countNum,0)infoConut,isnull(t5.countNum,0)debugConut from
(select convert(varchar(10),dateadd(dd,number,'2019/04/15'),111) as chartTime
from master..spt_values
where [type] = 'p' and number between 0 and datediff(dd,'2019/04/15','2019/04/30')) t1
left join 
(
select CONVERT(varchar(100), OperatorTime, 111)as logTime,count(OperatorTime)countNum from 
SysErrorLog as a
where Loglevel='Error' and a.OperatorTime between '2019/04/15' and '2019/04/30'
group by a.OperatorTime
)t2 
on t1.chartTime =t2.logTime
left join
(
select CONVERT(varchar(100), OperatorTime, 111)as logTime,count(OperatorTime)countNum from 
SysErrorLog as a
where Loglevel='Warn' and a.OperatorTime between '2019/04/15' and '2019/04/30'
group by a.OperatorTime
)t3
on t1.chartTime=t3.logTime
left join
(
select CONVERT(varchar(100), OperatorTime, 111)as logTime,count(OperatorTime)countNum from 
SysErrorLog as a
where Loglevel='Info' and a.OperatorTime between '2019/04/15' and '2019/04/30'
group by a.OperatorTime
)t4
on t1.chartTime=t4.logTime
left join
(
select CONVERT(varchar(100), OperatorTime, 111)as logTime,count(OperatorTime)countNum from 
SysErrorLog as a
where Loglevel='Debug' and a.OperatorTime between '2019/04/15' and '2019/04/30'
group by a.OperatorTime
)t5
on t1.chartTime=t5.logTime

3,结果表
【sql】SQL日期的自动补全填充_第2张图片
4,结果表-前端效果展示
在这里插入图片描述

你可能感兴趣的:(sql,server)