Log Parser Studio:按月统计 500 个错误和非错误
Log Parser Studio: Counts of 500 errors and non-errors by month
正在解析 w3c 日志,我想获取 500 个错误的计数,而不是每个月的计数。
这给出了每月 500 秒的计数:
SELECT TO_STRING(date, 'yyyy-MM') AS yearMonth, COUNT(*) AS HowMany
FROM '[LOGFILEPATH]'
WHERE cs-uri-stem LIKE '%pageIcareabout%'
AND sc-status = 500
GROUP BY yearMonth
将 sc-status = 500
更改为 sc-status <> 500
给出非 500 的计数。
但是,我不知道如何将 500s 和非 500s 显示为每个月的单独列。
您似乎想使用 CASE
语句:
SELECT TO_STRING(date, 'yyyy-MM') AS yearMonth, MyStatus, COUNT(*) AS HowMany
USING CASE sc-status WHEN 500 THEN '500' ELSE 'Not500' END AS MyStatus
FROM ...
WHERE cs-uri-stem LIKE '%pageIcareabout%'
GROUP BY yearMonth, MyStatus
我最终得到了这个:
SELECT
TO_STRING(date, 'yyyy-MM') AS yearMonth
, SUM(500) AS 500s
, SUM(Not500) AS Not500s
USING
CASE sc-status WHEN 500 THEN 1 ELSE 0 END AS 500
, CASE sc-status WHEN 500 THEN 0 ELSE 1 END AS Not500
FROM '[LOGFILEPATH]'
WHERE cs-uri-stem LIKE '%pageIcareabout%'
GROUP BY yearMonth
结果正是我想要的 -- 3 列,yearMonth、500s 和 Not500s,最后 2 列是当月它们各自值的计数。
正在解析 w3c 日志,我想获取 500 个错误的计数,而不是每个月的计数。 这给出了每月 500 秒的计数:
SELECT TO_STRING(date, 'yyyy-MM') AS yearMonth, COUNT(*) AS HowMany
FROM '[LOGFILEPATH]'
WHERE cs-uri-stem LIKE '%pageIcareabout%'
AND sc-status = 500
GROUP BY yearMonth
将 sc-status = 500
更改为 sc-status <> 500
给出非 500 的计数。
但是,我不知道如何将 500s 和非 500s 显示为每个月的单独列。
您似乎想使用 CASE
语句:
SELECT TO_STRING(date, 'yyyy-MM') AS yearMonth, MyStatus, COUNT(*) AS HowMany
USING CASE sc-status WHEN 500 THEN '500' ELSE 'Not500' END AS MyStatus
FROM ...
WHERE cs-uri-stem LIKE '%pageIcareabout%'
GROUP BY yearMonth, MyStatus
我最终得到了这个:
SELECT
TO_STRING(date, 'yyyy-MM') AS yearMonth
, SUM(500) AS 500s
, SUM(Not500) AS Not500s
USING
CASE sc-status WHEN 500 THEN 1 ELSE 0 END AS 500
, CASE sc-status WHEN 500 THEN 0 ELSE 1 END AS Not500
FROM '[LOGFILEPATH]'
WHERE cs-uri-stem LIKE '%pageIcareabout%'
GROUP BY yearMonth
结果正是我想要的 -- 3 列,yearMonth、500s 和 Not500s,最后 2 列是当月它们各自值的计数。