title: How to use SUM aggragate functions in Azure Cosmos DB
body: <p>As described in the <a href="https://docs.microsoft.com/en-us/azure/cosmos-db/sql-query-aggregates" rel="nofollow noreferrer">official documentation</a>, Cosmos Db SQL API support for aggregate functions. However, I could not find any decent query example which performs aggregate against items' multi-level document structure. 
  This is the structure of my Cosmos DB container items.  I am using SQL API</p>
  
  <pre><code>{
  "id": "1",
  "invoiceNo": "INV0001",
  "date": "2019/12/20",
  "userId": "cashier1",
  "invoiceDetails": [
      {
          "itemName": "Item 1",
          "qty": 1,
          "unitPrice": 100,
          "lineTotal": 100
      },
      {
          "itemName": "Item 2",
          "qty": 3,
          "unitPrice": 200,
          "lineTotal": 600
      },
      {
          "itemName": "Item 6",
          "qty": 1,
          "unitPrice": 300,
          "lineTotal": 300
      }
  ],
  "_rid": "h9Q6AKtS7i0BAAAAAAAAAA==",
  "_self": "dbs/h9Q6AA==/colls/h9Q6AKtS7i0=/docs/h9Q6AKtS7i0BAAAAAAAAAA==/",
  "_etag": "\"1500611a-0000-1800-0000-5e00fbd40000\"",
  "_attachments": "attachments/",
  "_ts": 1577122772
  </code></pre>
  
  <p>}</p>
  
  <p>I want to get the sum of invoiceDetails.lineTotal using a SQL query. Your answers are highly appreciated </p>