我正在解析一些IIS服务器日志(使用LogParser),我在创建一个查询时遇到了一些麻烦,该查询将为每种类型的浏览器(用户代理)提供总计数。
到目前为止,这是我的查询:
SELECT COUNT(*) as totalHits, CS(User-Agent) as browser
FROM E:\Logs\ex111101.log
WHERE (CS(User-Agent) LIKE '%ipad%'
OR CS(User-Agent) LIKE '%iphone%'
OR CS(User-Agent) LIKE '%blackberry%'
OR CS(User-Agent) LIKE '%windows cs%'
OR CS(User-Agent) LIKE '%android%')
AND cs-uri-stem LIKE '%.asp%'
GROUP BY browser
ORDER BY totalHits DESC
这给了我一个像我想要的用户代理列表,并为每组浏览器提供了一个命中数:
Total Hits | Browser
467 | AndroidA
45 | AndroidB
23 | BlackberryC
233 | BlackberryD
我想要的是这个:
Total Hits | Browser
512 | Android
256 | Blackberry
所有Android条目都在通用Android行下统计和计算。在这种情况下,Android的Total Hits将是467 + 45,Blackberry将是233 = 33等等。
从那里我想为每个浏览器提供一个百分比列,以便我可以用百分比表示总点击数。
感谢任何帮助。谢谢!
*的更新
遵循以下建议,但必须进行一些调整才能使LogParser正确执行。由于某种原因,Log Parser不喜欢CASE语句中的LIKE关键字。以下工作正常:
select
case strcnt(TO_LOWERCASE(cs(user-agent)),'android') WHEN 1 THEN 'Android' else
case strcnt(TO_LOWERCASE(cs(user-agent)),'ipad') WHEN 1 THEN 'iPad' else
case strcnt(TO_LOWERCASE(cs(user-agent)),'blackberry') WHEN 1 THEN 'Blackberry' else
case strcnt(TO_LOWERCASE(cs(user-agent)),'windows ce') WHEN 1 THEN 'Windows' else
case strcnt(TO_LOWERCASE(cs(user-agent)),'iphone') WHEN 1 THEN 'iPhone'
ELSE 'Non-Mobile' End End End End End as Browser,
count(*) as TotalHits
from MYLOG
group by Browser
order by TotalHits desc
答案 0 :(得分:7)
试
select
case when cs(User-Agent) like "%android%" then "Android"
when cs(User-Agent) like "%black%" then "Blackberry"
when cs(User-Agent) like "%windows%" then "Windows"
when cs(User-Agent) like "%iphone%" then "iPhone"
else "Other" end as Browser,
count(*) as TotalHits
from
YourTable.logFile
group by
Browser
order by
TotalHits desc
按顺序列出顺序列顺序而不是重新复制整个案例/何时计数(*)...因为只有两列,没有问题......