title: Get percentage average
body: <p>I'm unsure how to go about this either because it late, or I'm a MySQL noob (probably both to be honest).</p>
  
  <p>I have a table called 'poll_votes' which comprises of: </p>
  
  <pre><code>ID, poll_id, answer_id, ip, time_posted
  </code></pre>
  
  <p>What I need to do, is for each unique answer_id in a specific poll_id, calculate the percentage out of the total number of answers that the answer_id counts for. I'm not really good at wording what I need to do, so here is what the query should return (single row):</p>
  
  <pre><code>total -&gt; total number of answers for this poll_id
  [0] -&gt; the percentage of 'total' that this makes up eg. 32 (%)
  [1] -&gt; the percentage of 'total' that this makes up eg. 16 (%)
  [2] -&gt; the percentage of 'total' that this makes up eg. 52 (%)
  </code></pre>
  
  <p>Obviously, all the percentages added together should equal one hundred. Also to note, that the field names for each percentage returned are not necessarily in any order.</p>
  
  <p>I mean even if the query just returned the total and the number of votes for each answer_id, I'd be able to calculate it easily in PHP.</p>
  
  <p>Could anyone give me any pointers?</p>
  
  <p>Edit: This is what I have so far, but it doesn't work:</p>
  
  <pre><code>SELECT (SELECT COUNT(*) FROM poll_votes) AS total, answer_id, COUNT(answer_id) / total * 100 AS percentage GROUP BY answer_id
  </code></pre>