title: MySQL Math Functions - Get Percentage Done - (Add 2 Columns, divide and multiply)
body: <p>Im trying to calculate a percentage in a MySQL query.</p>
  
  <p>I have a table:</p>
  
  <pre><code>Table: Domains
  id   url_count   checked   tablekey_id
  1    2           1         10
  2    1           2         10
  3    1           1         15
  4    2           1         22
  5    2           2         10
  </code></pre>
  
  <p>So the math is :</p>
  
  <pre><code>((SUM of the `url_count` column where `checked` &gt;= 2 and `tablekey_id` = 10) / (SUM of the `url_count` column where `tablekey_id` = 10)) *100)
  </code></pre>
  
  <p>The numbers for the above equation would look like:
      (3 / 5) * 100 = 60%</p>
  
  <p>Thanks a bunch guys! I didn't realize you could put an if statement inside of the SUM. I worded my original question terribly so I wanted to post my solution in case someone is having the same issue. </p>
  
  <pre><code>SELECT (
  (SUM(IF(`checked` &gt;= 1, `url_count`, 0)) / SUM(`url_count`))*100
  ) AS percent
  FROM `google_sort_backlink_domains`
  WHERE `tablekey_id` = 10
  </code></pre>