Selecting an embeddedmap element from an embeddedlist attribute

24 Views Asked by At

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"?

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 
1

There are 1 best solutions below

0
AVK On

Got the answer from GitHub's project. 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