title: Returning total percentage within a group
body: <p>Using this sample database: <a href="https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_avg" rel="nofollow noreferrer">https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_avg</a></p>
  
  <p>I am trying to create a table that returns the percentage of orders per category, for each country. So it would look ideally something like this:</p>
  
  <pre><code>Country   CategoryName  Num_of_orders  % of orders
  Argentina  Confections       1            0.50
  Argentina   Produce          1            0.50
  Austria    Beverages         5            0.17
  Austria    Condiments        6            0.21
  </code></pre>
  
  <p>So since Argentina has only had two orders, Confections will be 50%, and so will produce.</p>
  
  <p>So far the closest I have gotten is returning a percentage of the total order count, but ignoring the countries.</p>
  
  <pre><code>SELECT c.country, ca.categoryname, count(o.orderid) as Num_of_orders, 
      count(*)/(select 1.0*count(*) from orders) as percentage
  from orders as o
  join customers as c on c.customerid = o.customerid
  join orderdetails as od on od.orderid = o.orderid
  join products as p on p.productid = od.productid
  join categories as ca on ca.categoryid = p.categoryid
  group by 1, 2
  </code></pre>
  
  <p>Any help would be appreciated.</p>