title: How to use a Count window function to get a percentage?
body: <p>Say I have the following table and values:</p>
  
  <pre><code>CREATE TABLE test (
    context text
  );
  
  INSERT INTO test VALUES ('idea'), ('vote'), ('vote'), ('query'), ('vote');
  </code></pre>
  
  <p>I want to be able to find out what percentage of the rows in the table are equal to <code>vote</code> without using a subquery in the select statement (which correct me if I'm off on this, will re-calculate for every row in the result set).</p>
  
  <p>I'm trying something like this:</p>
  
  <pre><code>SELECT context, count(*) / count(*) OVER ()::DOUBLE PRECISION AS pct
  FROM test
  GROUP BY context
  </code></pre>
  
  <p>but having no success. I would hope to see something like:</p>
  
  <p><code>context_name</code> <code>pct_of_total</code> for each distinct context type.</p>