我想将时间段从“1 小时”更改为“10 分钟”。
并将显示时间从“10”更改为“10:00”
declare @periodStart datetime
declare @periodEnd datetime
set @periodStart = CONVERT(varchar(10), GETDATE() - 1, 120)
set @periodEnd = CONVERT(varchar(10), GETDATE() , 120)
set @periodStart = dateadd(HH, datepart(HH,@periodStart), convert(varchar(12),@periodStart,112))
set @periodEnd = dateadd(HH, datepart(HH,@periodEnd), convert(varchar(12),@periodEnd,112))
;with dh
as
(
select top 144
DATEADD(HOUR,ROW_NUMBER() OVER (ORDER BY [Object_id])-1,convert(varchar(12),@periodStart,112)) as HoDstart,
DATEADD(HOUR,ROW_NUMBER() OVER (ORDER BY [Object_id]),convert(varchar(12),@periodStart,112)) as HoDend,
ROW_NUMBER() OVER (ORDER BY Object_id)-1 as DayHour
from sys.columns
)
select d.DayHour, count(f.Hostname) as 'Counter'
from dh d
left join FileBackup f
on f.StartTime < d.HoDend
and f.EndTime >= d.HoDstart
where d.HoDstart between @periodStart and @periodEnd
group by d.DayHour
order by d.DayHour