title: subquery the same table in select statement
body: <p>I have a resturant db and I need to total up the total value of all the items sold individually. So if I sold a hamburger that has a base price of $10.00 with bacon which costs $1.00 and a hambuger(again $10.00) with avacado that costs $0.50 I need to get $21.50 returned. My invoice table looks like this:</p>
  
  <pre><code>invoice_num item_num  price   item_id   parent_item_id
  111         hmbg      10.00   guid_1    ''
  111         bacn      1.00    guid_2    guid_2
  112         hmbg      10.00   guid_3    ''
  112         avcd      0.50    guid_4    guid_3
  </code></pre>
  
  <p>I can get the sum of all the parent items like this:</p>
  
  <pre><code>SELECT item_num, SUM(price) FROM invoices WHERE parent_item_id = ''
  </code></pre>
  
  <p>it is the adding of the toppings that is confusing me. I feel like I need to add a subquery in the SUM but I'm not sure how to go about doing it and referencing the original query to use the item_id.</p>