title: how to calculate the percentage ratio of two columns in sql server?
body: <p>I have the following query which is supposed to return the number of passed and failed activities. </p>
  
  <p>I'm stock at calculating the percentage ratio between the failed and passed activities for each row, as you can see right now I am returning 0.</p>
  
  <p>any help is much appreciated. </p>
  
  <p>query:</p>
  
  <pre><code>WITH CTE 
  AS(
      select activityid,
      SUM(CASE WHEN success = 1 THEN 1 ELSE 0 END) AS Pass, 
      SUM(CASE WHEN success = 0 THEN 1 ELSE 0 END) AS Fail
      from mytable
      group by activityid
  )
  select activityid, pass, fail,
  0 as passPercentage, 0 failPercentage
  from cte
  </code></pre>
  
  <p>resultset:</p>
  
  <pre><code>activityid  pass    fail    passPercentage   failPercentage
  1            26      22      0                    0
  2            23      29      0                    0
  </code></pre>