我想像下面的查询一样运行
SELECT round(sum (ARRAY_SUM(case when ANY x IN transactions SATISFIES
x.type` `in [0,4] then transactions[*].amount else 0 end))),2)
total_income,_type` `FROM mybucket WHERE _type='Company'
我有多个json,如下面
{
"_type": "Company",
"created": "2015-12-01T18:30:00.000Z",
"transactions": [
{
"amount": "96.5",
"date": "2016-01-03T18:30:00.000Z",
"type": 0
},
{
"amount": "483.7",
"date": "2016-01-10T18:30:00.000Z",
"type": 0
}
]
}
我想要交易的总和 - >在[0,1]中有类型的金额我希望它在条件条件下。我该怎么办?
答案 0 :(得分:1)
SELECT CASE WHEN array_count(a) > 0 THEN ARRAY_SUM(a) ELSE 0 END
FROM default
LET a = ARRAY TONUMBER(x.amount) FOR x in transactions WHEN x.type IN [0,4] END
WHERE _type = "Company";
答案 1 :(得分:0)