我试图找出一周内平均每秒IIS调用(GET,POST,PUT等)的平均次数
这是一个SELECT的示例,我将用它来获取一周内的总数:
SELECT Method, COUNT(*)
AS TotalCalls
FROM IISLog
WHERE dDate
BETWEEN '2018-05-10'
AND '2018-05-17'
GROUP BY Method
如何在此日期范围内细化此SELECT以获得平均每秒的方法调用计数?
每秒呼叫的预期输出:
Method CallsPerSecond
Get 15
Put 10
Post 14
Delete 12
数字只是示例估算值
答案 0 :(得分:2)
只需除以构成过滤器范围的秒数即可。
DECLARE @StartDate DATETIME = '2018-05-10'
DECLARE @EndDate DATETIME = '2018-05-17'
SELECT
Method,
CallsPerSecond = COUNT(*) / NULLIF(DATEDIFF(SECOND, @StartDate, @EndDate), 0),
TotalCalls = COUNT(*)
FROM
IISLog AS I
WHERE
I.dDate BETWEEN @StartDate AND @EndDate
GROUP BY
I.Method