标签:结束 span int style 多次 where max 函数 最大值
-- 数据量比较大的情况,统计十分钟内每秒钟执行次数
declare @begintime varchar(100); -- 开始时间 declare @endtime varchar(100); -- 结束时间 declare @num int; -- 结束时间 set @begintime = ‘2019-08-10 09:10:00‘ -- 开始时间 set @endtime = ‘2019-08-10 09:20:00‘ -- 结束时间 set @num = (select count(1) from PM_SYS_LOGINLOG where CONVERT(varchar(100),loginTime, 20) >= @begintime and CONVERT(varchar(100),loginTime, 20) <= @endtime) print(@num) select @num as 总条数, AVG(调用总数) as 十分钟内每秒平均执行次数 from (select s.请求时间, (调用一次的总数+ ( select 调用多次 from ( select 请求时间, COUNT(1) 调用多次 from ( select CONVERT(varchar(100),loginTime, 20) as 请求时间, count(1) as 调用次数 from PM_SYS_LOGINLOG where CONVERT(varchar(100),loginTime, 20) >= @begintime and CONVERT(varchar(100),loginTime, 20) <= @endtime group by loginTime having count(1) > 1) o where 请求时间 = s.请求时间 group by o.请求时间 ) o ) ) as 调用总数 from ( select t.请求时间, count(1) as 调用一次的总数 from ( select CONVERT(varchar(100),loginTime, 20) as 请求时间, count(1) as 调用次数 from PM_SYS_LOGINLOG where CONVERT(varchar(100),loginTime, 20) >= @begintime and CONVERT(varchar(100),loginTime, 20) <= @endtime group by loginTime having count(1) = 1 ) t group by 请求时间 ) s ) m
查询前一秒执行次数
declare @str varchar(100); set @str = convert(varchar,dateadd(ss,-1,getdate()),20) --select @str --print(@str) select @str as 执行时间, count(1) + ( select count(1) from (select top 20 CONVERT(varchar(100),loginTime, 20) as 请求时间, count(1) as 调用次数 from PM_SYS_LOGINLOG where CONVERT(varchar(100),loginTime, 20) = @str group by loginTime having count(1) = 2 order by loginTime desc) as o ) as 执行次数 from ( select top 20 CONVERT(varchar(100),loginTime, 20) as 请求时间, count(1) as 调用次数 from PM_SYS_LOGINLOG where CONVERT(varchar(100),loginTime, 20) = @str group by loginTime --having count(1) = 1 order by loginTime desc ) t
聚合函数分组查询最大值
select max(t.总数) as 最大值 from (select Token as 令牌, count(1) as 总数 from PM_SYS_LOGINLOG group by token having count(1) > max(1)) as t
select top 1 count(1) as 总数 from PM_SYS_LOGINLOG group by token having count(1) > 1 order by 总数 desc
sql server 大数据, 统计分组查询,数据量比较大计算十分钟内每秒钟执行次数
标签:结束 span int style 多次 where max 函数 最大值
原文地址:https://www.cnblogs.com/FGang/p/11330736.html