title: Calculating ratios in postgresql
body: <p>I new to postgresql and I am trying do calculate a rate in a table like this:</p>
  <pre><code>class  phase
  a      sold
  b      stock
  c      idle
  d      sold
  </code></pre>
  <p>I want to calculate  the <code>total count of sold phases / total</code>  like this:</p>
  <pre><code>2/4 = 50%
  </code></pre>
  <p>i was trying:</p>
  <pre><code>with t as ( select count(class) as total_sold from table where phase='sold')
  
  select total_sold / count(*) from t
  group by total_sold
  </code></pre>
  <p>but the result is wrong.  How can I do this?</p>