开发者社区> 问答> 正文

阿里云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 3697 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
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
SQL Server 2017 立即下载
GeoMesa on Spark SQL 立即下载
原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载

相关镜像