想要在使用N1QLCouchbase时将内部元素与JSON相加 [英] want to sum inner element with JSON in using N1QLCouchbase

查看:90
本文介绍了想要在使用N1QLCouchbase时将内部元素与JSON相加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在查询下面运行

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

I get multiple json like this

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

结果: [ { "$ 1":空 } ]

Result: [ { "$1": null } ]

现在,我想总结所有这些.我该怎么做?

Now I want to sum of all this. How can I do it?

推荐答案

transactions [*].这是返回数组,因此首先需要用户数组功能

transactions[*].amount this is return array so first need to user array function

ARRAY_SUM

比使用如下所示的总和.

than use sum like below.

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

这篇关于想要在使用N1QLCouchbase时将内部元素与JSON相加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆