聚合 和 分组聚合:

PlayMorphia 它提供了基于开发人员models的友好接口

设想你定义了一个model。class Sales:

@Entity public class Sales extends Model {
public String employeeId;
public String department;
public String region;
public int amount;
}

聚合:如今你能够在Sales模型上做聚合操作,以下是一些详细演示样例:

long total = Sales.count(); // also Sales.q().count();
long cntIT = Sales.q().filter("department", "IT").count();
long cntAU = Sales.q().filter("region", "AU").count();
long cntAuIt = Sales.find("region, department", "AU", "IT").count();

求和:

long sum = Sales._sum("amount"); // also Sales.q().sum("amount");
long sumIT = Sales.find("department", "IT").sum("amount");
long sumAU = Sales.find("region", "AU").sum("amount");
long sumAuIt = Sales.find("region department", "AU", "IT").sum("amount");

最大值:

long max = Sales._max("amount"); // also Sales.q().max("amount");
long maxIT = Sales.find("department", "IT").max("amount");
long maxAU = Sales.find("region", "AU").max("amount");
long maxAuIt = Sales.find("region department", "AU", "IT").max("amount");

最小值:

long min = Sales._min("amount"); // also Sales.q().min("amount");
long minIT = Sales.find("department", "IT").min("amount");
long minAU = Sales.find("region", "AU").min("amount");
long minAuIt = Sales.find("region department", "AU", "IT").min("amount");

分组聚合:

每个聚合都会相应一个分组聚合的接口,就像SQL中的group by语句

分组计数:

// group by region
AggregationResult byRegion = Sales.groupCount("region");
System.out.println("AU count: " + byRegion.get("region", "AU");
// group by department
AggregationResult byDep = Sales.groupCount("department");
System.out.println("IT count: " + byDep.get("department", "IT");
// group by region and department
AggregationResult byRegionDep = Sales.groupCount("region, department");
System.out.println("IT count: " + byRegionDep.get("department, region", "IT", "AU");

分组求和:

// group by region
AggregationResult byRegion = Sales.groupSum("region");
System.out.println("AU sum: " + byRegion.get("region", "AU");
// group by department
AggregationResult byDep = Sales.groupSum("department");
System.out.println("IT sum: " + byDep.get("department", "IT");
// group by region and department
AggregationResult byRegionDep = Sales.groupSum("region, department");
System.out.println("IT sum: " + byRegionDep.get("department, region", "IT", "AU");

分组求最大值:

// group by region
AggregationResult byRegion = Sales.groupMax("region");
System.out.println("AU max: " + byRegion.get("region", "AU");
// group by department
AggregationResult byDep = Sales.groupMax("department");
System.out.println("IT max: " + byDep.get("department", "IT");
// group by region and department
AggregationResult byRegionDep = Sales.groupMax("region, department");
System.out.println("IT max: " + byRegionDep.get("department, region", "IT", "AU");

分组求最小值:

// group by region
AggregationResult byRegion = Sales.groupMin("region");
System.out.println("AU min: " + byRegion.get("region", "AU");
// group by department
AggregationResult byDep = Sales.groupMin("department");
System.out.println("IT min: " + byDep.get("department", "IT");
// group by region and department
AggregationResult byRegionDep = Sales.groupMin("region, department");
System.out.println("IT min: " + byRegionDep.get("department, region", "IT", "AU");

原文链接:http://www.playframework.com/modules/morphia-1.2.9/statistics

Play Modules Morphia 1.2.9a 之 Aggregation and Group aggregation的更多相关文章

  1. UML中关联(Association)、聚合(Aggregation)和合成(Composition)之间的区别

    本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 现在,我们需要设计一个项目管理系统,目前我们收集到了如下这些需求: REQ1:一个项目内有多名项目成 ...

  2. 开发中使用mongoTemplate进行Aggregation聚合查询

    笔记:使用mongo聚合查询(一开始根本没接触过mongo,一点一点慢慢的查资料完成了工作需求) 需求:在订单表中,根据buyerNick分组,统计每个buyerNick的电话.地址.支付总金额以及总 ...

  3. 机器学习技法之Aggregation方法总结:Blending、Learning(Bagging、AdaBoost、Decision Tree)及其aggregation of aggregation

    本文主要基于台大林轩田老师的机器学习技法课程中关于使用融合(aggregation)方法获得更好性能的g的一个总结.包含从静态的融合方法blending(已经有了一堆的g,通过uniform:voti ...

  4. 网站行为跟踪 Website Activity Tracking Log Aggregation 日志聚合 In comparison to log-centric systems like Scribe or Flume

    网站行为跟踪 Website Activity Tracking 访客信息处理 Log Aggregation   日志聚合 Apache Kafka http://kafka.apache.org/ ...

  5. ansible common modules

    ##Some common modules[cloud modules] [clustering modules] [command modules]command - executes a comm ...

  6. 1.2 Use Cases中 Log Aggregation官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Log Aggregation 日志聚合 Many people use Kafka ...

  7. 使用aggregation API扩展你的kubernetes API

    Overview What is Kubernetes aggregation Kubernetes apiserver aggregation AA 是Kubernetes提供的一种扩展API的方法 ...

  8. MySQL vs. MongoDB: Choosing a Data Management Solution

    原文地址:http://www.javacodegeeks.com/2015/07/mysql-vs-mongodb.html 1. Introduction It would be fair to ...

  9. Hadoop记录-hdfs转载

    Hadoop 存档 每个文件均按块存储,每个块的元数据存储在namenode的内存中,因此hadoop存储小文件会非常低效.因为大量的小文件会耗尽namenode中的大部分内存.但注意,存储小文件所需 ...

随机推荐

  1. 服务器编程入门(10)TCP回射服务器实现 - 并发

    问题聚焦:     在前面我们大概浏览了一下服务器编程需要掌握的一些知识和技术,以及架构思想.        实践,才是检验真理的唯一标准..从这节起我们将在这些技术的基础上,一步步实现以及完善一个服 ...

  2. IntelliJ IDEA 14 注册码生成java代码(转)

    https://confluence.jetbrains.com/display/IntelliJIDEA/Previous+IntelliJ+IDEA+Releases 分享几个license: ( ...

  3. Eclipse中的SVN的冲突解决方案详解

    版本冲突原因: 假设A.B两个用户都在版本号为100的时候,更新了kingtuns.txt这个文件,A用户在修改完成之后提交kingtuns.txt到服务器,这个时候提交成功,这个时候kingtuns ...

  4. 2014牡丹江——Hierarchical Notation

    problemId=5380" style="background-color:rgb(51,255,51)">题目链接 字符串模拟 const int MAXN ...

  5. POJ 1696 Space Ant(点积的应用)

    Space Ant 大意:有一仅仅蚂蚁,每次都仅仅向当前方向的左边走,问蚂蚁走遍全部的点的顺序输出.開始的点是纵坐标最小的那个点,開始的方向是開始点的x轴正方向. 思路:从開始点開始,每次找剩下的点中 ...

  6. ReactNavtive框架教程(2)

    , alignItems: 'center' } }); 标准的 CSS 属性.尽管用CSS比在IB设置UI样式的可视化要差.但总比在viewDidLoad()方法中用代码写要好一些. 然后增加下面代 ...

  7. Android编程之LayoutInflater的inflate方法实例

    假设你不关心其内部实现,仅仅看怎样使用的话,直接看这篇就可以. 接上篇,接下来,就用最最简单的样例来说明一下: 用两个布局文件main 和 test: 当中,main.xml文件为: <?xml ...

  8. HDU1176_免费馅饼【号码塔】

    免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  9. shell编程三大神器之awk

  10. 使用gSoap规避和改动ONVIF标准类型结构的解析

    ONVIF/gSoap依赖关系及问题 ONVIF是一组服务规范,标准參考 gSoap是一套基于实现SOAP通信接口的工具链 即是,当我们须要訪问ONVIF的Web Service或实现对ONVIF部分 ...