Azure cosmosdb CosmosDb查询复杂结构:小计

Azure cosmosdb CosmosDb查询复杂结构:小计,azure-cosmosdb,Azure Cosmosdb,在我的收藏中,我有这样的文件 { "purchase_order_number": "PO15428132600", "total_due": 4893.3929, "account_number": "Account2", "freight": 183.1626, "ttl": 2592000, "order_date": "Mon Jul 11 00:00:00 2005", "_attachments": "attachments/"

在我的收藏中,我有这样的文件

{
    "purchase_order_number": "PO15428132600",
    "total_due": 4893.3929,
    "account_number": "Account2",
    "freight": 183.1626,
    "ttl": 2592000,
    "order_date": "Mon Jul 11 00:00:00 2005",
    "_attachments": "attachments/",
    "subtotal": 6107.082,
    "id": "SalesOrder",
    "_ts": 1519575296,
    "items": [
      {
        "line_price": 5.7,
        "order_qty": 3,
        "currecny_code": "USD",
        "unit_price": 17.1,
        "currency_symbol": "$",
        "product_code": "A-123",
        "product_name": "Product 1"
      },
      {
        "line_price": 4.7,
        "order_qty": 4,
        "currecny_code": "USD",
        "unit_price": 15,
        "currency_symbol": "$",
        "product_code": "A-123",
        "product_name": "Product 1"
      },
      {
        "line_price": 1.7,
        "order_qty": 2,
        "currecny_code": "USD",
        "unit_price": 5.1,
        "currency_symbol": "$",
        "product_code": "A-123",
        "product_name": "Product 1"
      }
    ]
}
我不知道我是否可能是Cosmo的初学者,但有关系数据库的背景

我想能够做一个查询,让我从我的项目,我可以放置在一个自定义项的单位价格*订单数量总和

谢谢

您可以使用:

SELECT SUM(item.unit_price * item.order_qty) FROM item IN o.items 
或者,如果需要对订单进行筛选,并对项目进行求和,请使用JOIN子句展开数组

SELECT SUM(item.unit_price * item.order_qty) 
FROM order 
JOIN item IN order.items 
WHERE order.purchase_order_number = "PO15428132600"

谢谢。在python中调用启用跨分区查询的第二个查询会使跨分区查询只支持聚合的“值”。如果可能,我将尝试将查询存储为UDF