below I have a query that will get the most common user agents for a site from a table of user agents and a linked table of ip addresses:
SELECT count(*) as num, string FROM `useragent_ip`
left join useragents on useragent_id = useragents.id
group by useragent_id
having num > 2
order by num desc, string
Sometimes it will show me something like
25 Firefox
22 IE
11 Chrome
3 Safari
1 Spider 1
1 Spider 2
1 Spider 3
My question is if there is a way that since the numbers on the left represent percentages of a whole, and will grow with time, can I have part of the sql statement to show each group’s percentage of the whole? So that instead of using having num > 2 then I could do something that would say get the percentage of the total rows instead of just the number of rows?
Yes you can:
I removed the
having num > 2, because it didn’t seem to make sense.