开发者社区> 问答> 正文

阿里云mongodb字符串的数字求和sql怎么写?

阿里云mongodb字符串的数字求和sql怎么写?
对refundAmount进行求和
{

"_id" : "fde917136e0413ce17220cf0f1bb615465",
"transactionId" : "4ab94f611ec45640f89a161e3738b537f1",
"uniqueId" : "60002019322713511032171",
"refundId" : "126",
"merchantRefundId" : null,
"tradeTime" : "2019-03-07 13:51:10",
"refundTime" : "2019-03-08 10:03:13",
"currency" : "JPY",
"amount" : "16244",
"refundAmount" : "16244",
"tradeStatus" : "SUCCESS",
"refundStatus" : "3",
"chargebackStatus" : "UNFACHARGEBACK",
"remark" : null,
"port_status" : "refund",
"merchantNo" : "0021020",
"update_time" : "2019-06-17 21:51:03"

},...

展开
收起
游客3lwcf4wf7v7iq 2019-07-10 23:27:55 3689 0
1 条回答
写回答
取消 提交回答
  • db.collection.aggregate([
      {
        "$group": {
          "_id": null,
          "totalAmount": {
            "$sum": {
              "$toDouble": "$refundAmount"
            }
          },
          "count": {
            "$sum": 1
          }
        }
      }
    ])

    结果是

      {
        "_id": null,
        "count": 1,
        "totalAmount": 16244
      }
    2019-07-17 23:38:14
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Data as a Service - 数据即服务 -- MongoDB⾼级应⽤模式 立即下载
阿里云MongoDB云服务构建 立即下载
饿了么高级架构师陈东明:MongoDB是如何逐步提高可靠性的 立即下载