MongoDB divide 使用之mongotempalte divide

需求:求一组数的两个字段计算结果的平均值

如有一组这样的数:

               列名1 列名2 列名3

    第一组数   a       2       5

    第二组数   b       4       8

按照列名1分组后求列2/列3 的平均值

关键代码:

Aggregation agg =  Aggregation.newAggregation(

     Aggregation.match(),//这里写其他需要过滤的条件

     Aggregation.group("列名1").avg(Devide.valueOf("列名2").divideBy("列名3")).as("别名");

);


posted @ 2019-01-04 17:11  农夫果园  阅读(894)  评论(0编辑  收藏  举报