title: Advanced count with join SQL
body: <p>I have two tables, items &amp; categories, sample data below:</p>
  
  <pre><code>Items:
  Title    category_id
  Item A   1
  Item B   2
  Item C   3
  Item D   2
  Item E   3
  Item F   2
  
  Categories
  category_id   category
  1             wood
  2             plastic
  3             metal
  </code></pre>
  
  <p>What I need to do is to count the total number of items, then list how many are in each category and what % that is of the total</p>
  
  <p>I know I can count each item and total e.g.</p>
  
  <pre><code>select 
    count(*) as total, 
    sum(category_id=1) as cat_1, 
    sum(category_id=2
  .... etc etc
  </code></pre>
  
  <p>But is there a way to do it all without counting each (there maybe new categories added and would like this to stay working) and then joining with categories table to produce the name?</p>
  
  <p>Ideally this is what I'd like to return:</p>
  
  <pre><code>Category    how many    % of total
  wood        1           17%
  plastic     3           50%
  metal       2           33%
  
  Total       6           100%
  </code></pre>
  
  <p>(17% is 1/6th => 16.666666667% rounded).</p>