阿里云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"
},...
db.collection.aggregate([
{
"$group": {
"_id": null,
"totalAmount": {
"$sum": {
"$toDouble": "$refundAmount"
}
},
"count": {
"$sum": 1
}
}
}
])
结果是
{
"_id": null,
"count": 1,
"totalAmount": 16244
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。