2016-11-28 37 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 
    } 
    ] 
} 

我得到多個JSON這樣

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

結果: [ { 「$ 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; 
相關問題