我尝试使用查询(下面)生成一个表(查看表1)。
CREATE TABLE #temp(
[VisitingCount] int,
[Time] nvarchar(50) )
DECLARE @DateNow DATETIME,@i int
SET @DateNow='00:00'
set @i=1;
while(@i<1440)
begin
set @DateNow=DATEADD(minute, 1, @DateNow)
insert into #temp ([VisitingCount], [Time]) values(0, right(left(convert(nvarchar, @DateNow, 121), 16), 5))
set @i=@i+1
end
select Count(VisitingCount) as VisitingCount,[Time]
from
#temp as Alltimes
left outer join
( SELECT Page,Date,[user],
dbo.fn_GetActivityLogArranger2(Date,'hour') as [Time]
FROM scr_SecuristLog
) scr_SecuristLog
on Alltimes.[Time] = scr_SecuristLog.[Time]
where
Date between '2009-04-30' and '2009-05-02'
and
[user] in
( select USERNAME
from scr_CustomerAuthorities
where customerID=Convert(varchar,4)
and ID=Convert(varchar,43)
)
group by [Time] order by [Time] asc
drop table #temp
我需要这个结果(如下)。这个代码关于系统入口日志, 但是在12:30到13:30之间有一顿午餐。 所以在12:30到13:30之间不要进入我们的系统。 如果你绘制日志Graghic。由于突破间隙,你可以看到“M”字符
我的梦想表1结果:
计数--------- ---------时间答案 0 :(得分:2)
这是你的where子句,是什么过滤了一些时间范围。 您需要为内部选择设置该子句:
select Count(VisitingCount) as VisitingCount,[Time]
from
#temp as Alltimes
left outer join
( SELECT Page,Date,[user],
dbo.fn_GetActivityLogArranger2(Date,'hour') as [Time]
FROM scr_SecuristLog
where Date between '2009-04-30' and '2009-05-02'
and
[user] in
( select USERNAME
from scr_CustomerAuthorities
where customerID=Convert(varchar,4)
and ID=Convert(varchar,43)
)
) scr_SecuristLog
on Alltimes.[Time] = scr_SecuristLog.[Time]
group by [Time] order by [Time] asc