title: How to Calculate percentage in MySQL
body: <p>I have a database like this image,</p>
  
  <pre><code>id      q_id     body    user_id  thread
  338222  433798  Testing    7178     1
  338223  433798  Testing    5571     1
  338224  433798  Testing    5571     1
  </code></pre>
  
  <p>And my query looks like this, </p>
  
  <pre><code>SELECT 
  thread, 
  user_id, 
  COUNT(*) AS contribution FROM answers GROUP BY user_id, thread ORDER BY thread
  </code></pre>
  
  <p>Which will return thread, user_id and contribution. But I want to get the percentage of contribution. Let's say user_id 7178 contribute 1 times to thread 1 and thread 1 has 3 rows so the percentage will be 33.33%</p>
  
  <pre><code>thread  user_id contribution percentage
  1       7178         1         33.33
  1       5571         2         67.67 
  </code></pre>
  
  <p>How can I get that? Can anybody help me out?</p>