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
Play Modules Morphia 1.2.9a 之 Aggregation and Group aggregation的更多相关文章
- UML中关联(Association)、聚合(Aggregation)和合成(Composition)之间的区别
本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 现在,我们需要设计一个项目管理系统,目前我们收集到了如下这些需求: REQ1:一个项目内有多名项目成 ...
- 开发中使用mongoTemplate进行Aggregation聚合查询
笔记:使用mongo聚合查询(一开始根本没接触过mongo,一点一点慢慢的查资料完成了工作需求) 需求:在订单表中,根据buyerNick分组,统计每个buyerNick的电话.地址.支付总金额以及总 ...
- 机器学习技法之Aggregation方法总结:Blending、Learning(Bagging、AdaBoost、Decision Tree)及其aggregation of aggregation
本文主要基于台大林轩田老师的机器学习技法课程中关于使用融合(aggregation)方法获得更好性能的g的一个总结.包含从静态的融合方法blending(已经有了一堆的g,通过uniform:voti ...
- 网站行为跟踪 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/ ...
- ansible common modules
##Some common modules[cloud modules] [clustering modules] [command modules]command - executes a comm ...
- 1.2 Use Cases中 Log Aggregation官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Log Aggregation 日志聚合 Many people use Kafka ...
- 使用aggregation API扩展你的kubernetes API
Overview What is Kubernetes aggregation Kubernetes apiserver aggregation AA 是Kubernetes提供的一种扩展API的方法 ...
- 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 ...
- Hadoop记录-hdfs转载
Hadoop 存档 每个文件均按块存储,每个块的元数据存储在namenode的内存中,因此hadoop存储小文件会非常低效.因为大量的小文件会耗尽namenode中的大部分内存.但注意,存储小文件所需 ...
随机推荐
- C++:抽象基类和纯虚函数的理解
转载地址:http://blog.csdn.net/acs713/article/details/7352440 抽象类是一种特殊的类,它是为了抽象和设计的目的为建立的,它处于继承层次结构的较上层. ...
- 用VS2005编译生成Lua库文件和解释器
TMD,本来很简单的东西,网上说的乱七八糟,说的也不明白,大家抄来抄去,估计都不自己实践的..花了半个下午研究了一下,总结一下. 1)下载lua工程文件,地址为http://www.lua.org/f ...
- vi 按了ctrl+s之后
再windows不管是写程序.还是用Word写文件.已经习惯了按ctrl+s 保存代码. 在用vi的时候.常常无意中按了ctrl+s,结果就是如同终端死掉了一样. 这是由于ctrl+s 终止屏幕输出( ...
- 《JavaScript设计模式与开发实践》读书笔记之代理模式
1.代理模式 代理模式是为一个对象提供一个代用品或占位符,以便控制对它的访问 1.1 一般的图片加载 var myImage=(function () { var imgNode=document.c ...
- apache2.4.4启用deflate压缩
今天在看<高性能php应用开发>这本书,说道如何启用mod_deflate: 启用如下模块: LoadModule deflate_module modules/mod_deflate.s ...
- codeforces293E (树上点分治+树状数组)
和poj1747相比起来,只不过是限制条件多了一维. 而多了这一维,所以需要用树状数组来维护,从而快速得到答案. 因为没注意传进树状数组函数的参数可能是<=0的,导致超时了好久. #pragma ...
- 实现Android ListView 自动加载更多内容
研究了几个小时终于实现了Android ListView 自动加载的效果. 说说我是怎样实现的.分享给大家. 1.给ListView增加一个FooterView,调用addFooterView(foo ...
- PB数据库相关
---------------------------------------------------------------- 数据库画板: 一张表定义了主键或者唯一索引,则能够在Results视窗 ...
- Trie图
AC自动机是KMP的多串形式,当文本串失配时,AC自动机的fail指针告诉我们应该跳到哪里去继续匹配(跳到当前匹配串的最长后缀去),所以AC自动机的状态是有限的 但是AC自动机具有不确定性, 比如要求 ...
- LightOj 1148 Basic Math
1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB Mob ...