mysql查询选择不同记录的百分比

I have extracted browser records from access log file and inserted them into database.Now i need to display the most popular browsers and their percentages too so i need a query for that.Here is how the records look like:

  1. Mozilla/5.0 (compatible; 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

In the results table i want to show only browser/version without specifications in the brackets above and i need percentage too.

I have tried to use (count(distinct client)/sum(distinct client)*100) to calculate the percentage but it returns NULL.Can anyone help?

You can use like filter to extract the particular browser count. For ex. to get count for mozilla:

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

Hope it helps.. :)

Can you not do something like:

Select count(*) as count_of_browser_use, browser_type from stats_table Group by browser_type

Then just use PHP (or other language) to quickly do the maths?