title: Normalize data in SQL query
body: <p>I have an SQL query <code>A</code> (see below for more details) that returns a table as following:</p>
  
  <pre><code>cluster  brand  amount
  0         bos     600
  0         phi     300
  0         har     100
  1         pro    2500
  1         wal    1500
  1         ash    1000
  2         dil    4200
  2         sor     500
  2         van     300
  ...
  </code></pre>
  
  <p>However, I want to show not the amount, but the fraction of that amount compared to the total amount in that cluster, like in the following table:</p>
  
  <pre><code>cluster  brand  amount
  0         bos    0.60
  0         phi    0.30
  0         har    0.10
  1         pro    0.50
  1         wal    0.30
  1         ash    0.20
  2         dil    0.84
  2         sor    0.10
  2         van    0.06
  ...
  </code></pre>
  
  <p>How should I change my SQL such that I can get access to the sum over all amounts in one cluster, and still have multiple rows with the same cluster?</p>
  
  <p><strong>** Details **</strong></p>
  
  <p>SQL server: MySQL, interfaced through the python-MySQL connector.</p>
  
  <p>Current SQL query to generate the first table:</p>
  
  <pre><code>SELECT c.cluster, brand, COUNT(o.id) AS brand_amount
  FROM nyon_all.clustering AS c 
  LEFT JOIN nyon_all.persons AS p ON c.pid = p.id 
  LEFT JOIN nyon_all.orders AS o ON p.id = o.pid 
  LEFT JOIN nyon_all.articles AS a ON o.aid = a.id 
  LEFT JOIN nyon_all.brands AS ab ON a.brand_id = ab.id 
  WHERE c.cluster_round = 'Org_2014-08-27_10:45:35'
  GROUP BY cluster, brand 
  HAVING brand_amount &gt; 100
  ORDER BY c.cluster ASC, brand_amount DESC;
  </code></pre>
  
  <p>Table <code>orders</code> (primary key <code>id</code>) links <code>persons</code> (foreign key <code>pid</code>) with <code>articles</code> (foreign key <code>aid</code>). <code>Articles</code> have a certain brand (foreign key <code>brand_id</code>), which are related to a name in the Table <code>brands</code>.</p>
  
  <p>The total amount of articles per cluster can be retrieved with the following SQL query:</p>
  
  <pre><code>SELECT c.cluster, COUNT(o.pid) AS amount
  FROM nyon_all.clustering AS c 
  LEFT JOIN nyon_all.persons AS p ON c.pid = p.id 
  LEFT JOIN nyon_all.orders AS o ON p.id = o.pid 
  WHERE c.cluster_round = 'Org_2014-08-27_10:45:35'
  GROUP BY cluster
  ORDER BY c.cluster ASC, amount DESC;
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>cluster amount
  0        1000
  1        5000
  2        5000
  </code></pre>
  
  <p>However, I can't seem to combine the two SQL queries.</p>