简体   繁体   English

从内嵌清单属性中选择内嵌地图元素

[英]Selecting an embeddedmap element from an embeddedlist attribute

Supposedly there's a set of records where each record looks like the following: 假设有一组记录,每个记录如下所示:

{
    "total": 300,
    "items": [
       {
           "id": "item1",
           "amount": 100
       },
       {
           "id": "item2",
           "amount": 200
       },
    ]
}

Is it possible to do a sum of all totals and items with id = "item1"? 是否可以对id =“ item1”的所有总计和项目进行总和?

So basically, smth like this (i know that query is ultimately incorrect, but just to show the idea): 所以基本上,像这样(我知道查询最终是不正确的,但只是为了说明这个想法):

select sum(total) as total, sum(items(id="item1").amount) as item1Amount
from MyRecord 

Got the answer from GitHub's project. 从GitHub的项目中得到了答案。 Apparently my initial hypothetical query was quite close to what it should be. 显然,我最初的假设查询非常接近应有的条件。

Here's the answer: 答案是:

select sum(total) as total, sum(items[id="item1"].amount) as item1Amount
from MyRecord 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM