想在使用 N1QL Couchbase 时将内部元素与 JSON 相加
want to sum inner element with JSON in using N1QLCouchbase
当我 运行 下面查询
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”:空
}
]
现在我想总结一下所有这些。我该怎么做?
transactions[*].amount 这是 return 数组所以首先需要用户数组 function
ARRAY_SUM
不如像下面那样使用总和。
SELECT sum(ARRAY_SUM(transactions[*].amount)) FROM Inheritx WHERE ANY x IN transactions SATISFIES x.type in [0,4] END;
当我 运行 下面查询
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”:空 } ]
现在我想总结一下所有这些。我该怎么做?
transactions[*].amount 这是 return 数组所以首先需要用户数组 function
ARRAY_SUM
不如像下面那样使用总和。
SELECT sum(ARRAY_SUM(transactions[*].amount)) FROM Inheritx WHERE ANY x IN transactions SATISFIES x.type in [0,4] END;