mysql 查询到 select 百分比的不同记录

mysql query to select percentage of distinct records

我已经从访问日志文件中提取浏览器记录并将它们插入 database.Now 我需要显示最流行的浏览器及其百分比,所以我需要查询 that.Here 是如何记录的看起来像:

  1. Mozilla/5.0(兼容;AhrefsBot/5.0;+http://ahrefs.com/robot/

  2. Mozilla/5.0 (Windows NT 6.3; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0

  3. Opera/9.80 (Windows NT 6.1) Presto/2.12.388 Version/12.16

在结果中 table 我只想显示 browser/version 上面括号中没有说明,我也需要百分比。

我尝试使用 (count(distinct client)/sum(distinct client)*100) 来计算百分比,但它 returns NULL.Can 有人帮忙吗?

您可以使用 like 过滤器来提取特定的浏览器计数。对于前。获取 mozilla 的计数:

select (select count(*) from table_name where column_name like '%Mozilla%' count_mozilla)/(select count(*) from table_name total_count)*100 from dual

希望对您有所帮助..:)

你能不能不做这样的事情:

Select 计数 (*) 作为 count_of_browser_use,browser_type 来自 stats_table 按 browser_type

分组

然后就用PHP(或其他语言)快速算一下?