title: Calculate percentage between two tables with group by -SQL (Impala)
body: <p>I'm working on Impala (Cloudera) and I have two tables, Customers and Arrangements. Customer table has the following columns: </p>
  
  <pre><code>customercrs | customertype| 
  ------------+-------------+
   1000       | NP          |  
   100000     | NP          |   
   100001     | NP          |  
   100002     | GROUP       |  
   100023     | GROUP       |
   100024     | INDIRECT    |
  </code></pre>
  
  <p>Arrangement table:</p>
  
  <pre><code>customercrs | arrangementid| 
  ------------+--------------+
   1000       | 11000000361  |  
   100000     | 11000000370  |  
   100000     | 11000000434  |
   100000     | 11000000426  |
   100001     | 11000000418  | 
   100001     | 11000000400  |
   100001     | 11000000396  |
   100001     | 11000000388  |
   100002     | 11000000591  |  
   100002     | 11000000582  |
   100023     | 11000000574  |
   100024     | 11000000566  |
   100024     | 11000000558  |
  </code></pre>
  
  <p>I want to calculate the percentage of arrangements per customertype. Something like:</p>
  
  <pre><code>customertype | percentage  |
  -------------+-------------+
   NP          | 62%         |
   GROUP       | 23%         |
   INDIRECT    | 15%         |
  </code></pre>
  
  <p>I tried the following sql query, but it didn't work. Any idea?</p>
  
  <pre><code>select customertype, count(*)/(select count(*) from arrangements)
  from customers as a, arrangements_sample as b
  where a.customercrs = b.customercrs
  group by a.customertype
  </code></pre>
  
  <p>Thanks!!!</p>