我在网站上跟踪访问者国家/地区,并使用此mysql查询获取访问者所在国家/地区的最高名称。

mysql_query("SELECT id,country, count(*) as num FROM track GROUP BY country ORDER BY count(*) desc limit 5")


它完美地工作。但是,我想获得%s个国家/地区。我怎样才能做到这一点 ?

最佳答案

此联接将报告百分比:

select id, country, num, num*100/total pct
from (SELECT id,country, count(*) as num
      FROM track GROUP BY country
      ORDER BY num desc limit 5) x
join (select count(*) total from track) y

关于php - 获取最常用行值的%,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15778525/

10-13 08:53