牛骨文教育服务平台(让学习变的简单)
博文笔记

mongodb 聚合aggregate 乘法

创建时间:2017-02-15 投稿人: 浏览次数:2029

1.mongodb统计数据时需要两列相乘并且将相乘的结果求和的功能

2.代码:

db.shopprilegerecoding.aggregate([
 {$match :{$and:[{createtime:{"$gt":new Date("2017-01-01")}},{createtime:{"$lt":new Date("2017-12-31")}}]} },
 {$group : 
     {
         _id : {
        year:{$year:"$createtime"},
        month:{$month:"$createtime"},
         }, 
        num_tutorial : {$sum : {$multiply:["$price","$limit"]} }//此处price为单价,limit为数量
     }
  }
])

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。