Play Modules Morphia 1.2.9a 之 Aggregation and Group aggregation

聚合 和 分组聚合:

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

时间: 2024-12-28 01:51:22

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

Ruby操作MongoDB(进阶八)-聚合操作Aggregation

上篇博文讲述了排序规则collations的操作和设置方式.顺带介绍了一部分聚合aggregation的设置方式.本文继续介绍聚合操作. 聚合框架的操作处理完数据记录后在返回计算结果.集合操作将来源于多个文档的值归类到一起,这样就可疑在被归类的数据上进行多种操作,然后返回一个单独的结果 1 聚合管道 聚合管道是用于数据聚合的一个框架,是以数据处理管道概念为原型.将文档输入一个多级管道后,可疑将文档转换为聚合的结果.下面以restaurants作为数据集,通过将餐馆类归类,我们就可以使用聚合管道在

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 say that as IT professionals we are living in the golden age of data management era. As our software systems become more complex and more distributed,

mongodb维护常用命令

一,用户操作:1. #进入数据库adminuse admin2. #增加或修改用户密码db.addUser('name','pwd')3. #查看用户列表db.system.users.find()4. #用户认证db.auth('name','pwd')5. #删除用户db.removeUser('name')6. #查看所有用户show users7. #查看所有数据库show dbs8. #查看所有的collectionshow collections9. #查看各collection的状

H3C 5560和5110链路聚合

5560和5110链路聚合 注意:最好按照[建立聚合接口-重置物理接口并加入聚合组-在聚合组里做相关配置]的顺序来建立链路聚合,以防出现问题. 我发现这个二层链路聚合和三层链路聚合不同:三层聚合端口 物理端口下只有加入聚合组的配置,而二层聚合组还有从聚合口那复制出来的配置.比如trunk.这也是我之前配置不成功的原因.其实不按顺序也行,只要每个接口下的配置和按顺序来弄得配置一样就行. 在5560一侧 [HN-PY-Core-HX-S5560-1]interface Bridge-Aggregat

VRF-AWARE-----------------GETVPN配置

GM--GC的pre-shared-key cisco REKEY-------RSA:cciekey eigrp authentication:ccie STEP1:VRF配置 GM端: ip vrf xx rd xx:xx 2.int lo xx ip vrf forward xx ip add xx 3.int gi xx encapsulation dot1q xxx ip vrf forward xx ip add xxxx ip authentication mode eigrp x

模块化技术

声明:原创作品,转载时请注明文章来自SAP师太技术博客:www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将追究法律责任!原文链接:http://www.cnblogs.com/jiangzhengjun/p/4293465.html ABAP program结构... 199 Macros. 200 Include. 200 ABAP程序中的局部与全局变量... 200 Local Copies of Global Fields(Form中,全局变

系统运维篇之DellR720-配置Broadcom网卡组配置实例

首先,配置端口组在实际情况中的运用的场景很多,偏冗余主要为了解决单点故障问题.多是配合在HA.VRRP.hsrp,交换机堆叠等多种实际运用场景. 好了,不唠叨直接"上大菜" 第一大步: 配置Broadcom网卡组 要在Broadcom网卡上启用网卡组,需要安装Broadcom网卡管理软件BACS(Broadcom Advanced Control Suite),可以从Broadcom网站下载该软件,链接如下: http://www.broadcom.com/support/ethern

SaltStck 搭建Web集群运用示例 (二)

在上一篇文章中,我们了解了saltstack搭建Web集群的基础环境以及haproxy的部署,这里我们将想继续了解一下其他的web服务如何通过saltstack部署起来. 参考资料:https://github.com/unixhot/saltbook-code SaltStack部署keepalived 编写安装配置sls文件 在keepalived目标编写install.sls: [[email protected] /srv/salt/prod/modules/keepalived]# c

SaltStack安装Tomcat

1. 基础环境 [[email protected] ~]# cd /srv/salt/prod/modules [[email protected] modules]# ls haproxy  keepalived  memcached  pcre  pkg     user jdk      libevent    nginx      php   tomcat [[email protected] modules]# mkdir jdk && mkdir tomcat modules