title: Howe to calculate the weighted average price having multiple categories and subcategories?
body: <p><img src="https://i.stack.imgur.com/zeWtf.png" alt="enter image description here"></p>
  
  <p>I want to calculated the weighted average price in SQL for each level i.e. L0,L1, and L2. Currently, I only know the formula for calculating the general weighted avg = sum(price*units)/sum(units). </p>
  
  <pre class="lang-sql prettyprint-override"><code>    SELECT COALESCE((price*units)/units, 0) AS price_weighted
  </code></pre>
  
  <p>How should I roll it up to any category I want?</p>