开发者社区> 问答> 正文

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

游客3lwcf4wf7v7iq 2019-07-10 23:27:55 105

阿里云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"

},...

SQL NoSQL MongoDB
分享到
取消 提交回答
全部回答(1)
  • 湖畔之清风明月
    2019-07-17 23:38:14
    db.collection.aggregate([
      {
        "$group": {
          "_id": null,
          "totalAmount": {
            "$sum": {
              "$toDouble": "$refundAmount"
            }
          },
          "count": {
            "$sum": 1
          }
        }
      }
    ])

    结果是

      {
        "_id": null,
        "count": 1,
        "totalAmount": 16244
      }
    0 0
+ 订阅

分享数据库前沿,解构实战干货,推动数据库技术变革

推荐文章
相似问题
推荐课程