Compute ratio of group sizes using SQL
<p>Consider a simple group by query:</p>

<pre><code>select foo, count(*)
    from mytable where bar=10 
group by foo
</code></pre>

<p>This returns a table that has the following form:</p>

<pre><code>foo | count
----+------
a   | 100
b   | 200
c   | 300
</code></pre>

<p>My goal is to get, using a single query the following table:</p>

<pre><code>foo | count | ratio
----+-------+-------
a   | 200   | 18.2
b   | 300   | 27.3
c   | 600   | 54.5
</code></pre>

<p>In practice, I have more possible values of <code>foo</code> thus answers like those in <a href="https://stackoverflow.com/questions/27253333/how-to-calculate-ratio-using-sql-query">here</a> are not helpful. Furthermore, not that the ratio is rounded and multiplied by 100.</p>

<p>What is the best practice to do this?</p>