sql server 大数据, 统计分组查询,数据量比较大计算十分钟内每秒钟执行次数
Posted fgang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql server 大数据, 统计分组查询,数据量比较大计算十分钟内每秒钟执行次数相关的知识,希望对你有一定的参考价值。
-- 数据量比较大的情况,统计十分钟内每秒钟执行次数
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 大数据, 统计分组查询,数据量比较大计算十分钟内每秒钟执行次数的主要内容,如果未能解决你的问题,请参考以下文章