2016-11-28 5 views
0

를 사용하여 JSON와 내부 요소를 합계를내가 쿼리 아래 실행할 때 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 
    } 
    ] 
} 

내가 얻을이

SELECT sum(transactions[*].amount) FROM Inheritx WHERE ANY x IN transactions SATISFIES x.type in [0,4] END; 

결과와 같은 여러 JSON : [ { "$ 1": null } ]

지금 나는이 모든 것을 합치기를 원합니다. 내가 어떻게 해?

답변

0

트랜잭션 [*].이 복귀 배열 상당하므로 아래와 같이 사용 합보다 사용자 배열 함수

ARRAY_SUM 

에 먼저 필요하다.

SELECT sum(ARRAY_SUM(transactions[*].amount)) FROM Inheritx WHERE ANY x IN transactions SATISFIES x.type in [0,4] END;