title: PostgreSQL: SUM of JSON nested elements?
body: <p>I have a record that looks like this:</p>
  
  <pre><code>{
    "id": 93824701,
    "lines": [
      {"number": 1, "unit_price": 9.77},
      {"number": 2, "unit_price": 8.36}
    ]
  }
  </code></pre>
  
  <p>From the query:</p>
  
  <pre><code>select * from sales where sale @&gt; '{"id": 93824701}'::jsonb;
  </code></pre>
  
  <p>How do I calculate the sum of all the <code>unit_prices</code> elements (in SQL), so that the result would be <code>18.13</code>?</p>