title: How can I get the percentage of total rows with mysql for a group?
body: <p>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:</p>
  
  <pre><code>SELECT count(*) as num, string FROM `useragent_ip`
  left join useragents on useragent_id = useragents.id
  group by useragent_id
  having num &gt; 2
  order by num desc, string
  </code></pre>
  
  <p>Sometimes it will show me something like</p>
  
  <pre><code>25 Firefox
  22 IE
  11 Chrome
  3  Safari
  1  Spider 1
  1  Spider 2
  1  Spider 3
  </code></pre>
  
  <p>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 <code>having num &gt; 2</code> then I could do something that would say  get the percentage of the total rows instead of just the number of rows?</p>