当我在查询下面运行时
SELECT * FROM myBucket WHERE ANY x IN transactions SATISFIES x.type in [0,4] END;
结果:
{
"_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
}
]
}
我得到多个这样的json
SELECT sum(transactions[*].amount) FROM Inheritx WHERE ANY x IN transactions SATISFIES x.type in [0,4] END;
结果: [ { " $ 1":null } ]
现在我想要总结这一切。我该怎么做?
答案 0 :(得分:0)
transactions [*]。amount这是返回数组所以首先需要用户数组函数
ARRAY_SUM
比使用下面的总和。
SELECT sum(ARRAY_SUM(transactions[*].amount)) FROM Inheritx WHERE ANY x IN transactions SATISFIES x.type in [0,4] END;