Oracle Aggregate Functions用过很多,官网的说明如下:
Aggregate Functions
http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions003.htm#SQLRF20035
Aggregatefunctions return a single result row based on groups of rows, rather than onsingle rows. Aggregate functions can appear in select lists and inORDERBYandHAVINGclauses. They are commonly used with theGROUPBYclausein aSELECTstatement, where Oracle Database divides the rows of aqueried table or view into groups. In a query containing aGROUPBYclause,the elements of the select list can be aggregate functions,GROUPBYexpressions,constants, or expressions involving one of these. Oracle applies the aggregatefunctions to each group of rows and returns a single result row for each group.
--聚合函数根据group的情况,返回每个groups里的一个result。 聚合函数可以使用orderby 和 having 的子句中使用。
If you omit theGROUPBYclause,then Oracle applies aggregate functions in the select list to all the rows inthe queried table or view. You use aggregate functions in the HAVINGclauseto eliminate groups from the output based on the results of the aggregatefunctions, rather than on the values of the individual rows of the queriedtable or view.
--如果省略group by 子句,那么聚合函数针对查询表或视图的所有记录生效。
Many (but notall) aggregate functions that take a single argument accept these clauses:
一些聚合函数可以在子句中带一个参数,如:
(1)DISTINCTandUNIQUE,which are synonymous, cause an aggregate function to consider only distinctvalues of the argument expression. The syntax diagrams for aggregate functionsin this chapter use the keywordDISTINCTfor simplicity.
(2)ALLcauses an aggregatefunction to consider all values, including all duplicates.
For example, theDISTINCTaverageof 1, 1, 1, and 3 is 2. TheALLaverage is 1.5. If you specifyneither, then the default isALL.
Some aggregatefunctions allow thewindowing_clause, which is part of the syntax ofanalytic functions. Refer towindowing_clauseforinformation about this clause. In the listing of aggregate functions at the endof this section, the functions that allow thewindowing_clausearefollowed by an asterisk (*)
--一些aggregrate 函数允许使用开窗函数,开窗函数是分析函数的组成部分,在下面列出的aggregate functions 中,后面加星号的就是可以使用开窗子句的。
有关分析函数参考:
Oracle分析函数(Analytic Functions) 说明
http://blog.csdn.net/tianlesoftware/article/details/4795632
All aggregate functions exceptCOUNT(*),GROUPING,andGROUPING_IDignore nulls. You can use theNVLfunctionin the argument to an aggregate function to substitute a value for a null.COUNTandREGR_COUNTneverreturn null, but return either a number or zero. For all the remainingaggregate functions, if the data set contains no rows, or contains only rowswith nulls as arguments to the aggregate function, then the function returnsnull.
--除了count(*),grouping,和grouping_id外,所有的聚合函数都会忽略nulls。 当我们遇到Null 时,可以在聚合函数中使用NVL 函数来处理null。
Count 和Regr_count 聚合函数不会返回null,而是返回0或者某个数字。 其他的聚合函数当没有rows 则返回null。
NVL 用法:
NVL(eExpression1,eExpression2)
如果 eExpression1 的计算结果为 null 值,则 NVL( ) 返回 eExpression2。如果 eExpression1 的计算结果不是 null 值,则返回 eExpression1。eExpression1 和 eExpression2 可以是任意一种数据类型。如果 eExpression1 与 eExpression2 的结果皆为 null 值,则 NVL( ) 返回 NULL。
因此使用NVL可以过滤NULL值。
The aggregate functionsMIN,MAX,SUM,AVG,COUNT,VARIANCE,andSTDDEV, when followed by theKEEPkeyword, can be used inconjunction with theFIRSTorLAST function to operate on a setof values from a set of rows that rank as theFIRSTorLASTwithrespect to a given sorting specification. Refer toFIRSTformore information.
You can nestaggregate functions.
--聚合函数可以嵌套使用,示例如下:
For example, thefollowing example calculates the average of the maximum salaries of all thedepartments in the sample schemahr:
SELECT AVG(MAX(salary))
FROM employees
GROUP BY department_id;
AVG(MAX(SALARY))
----------------
10926.3333
This calculation evaluates the inner aggregate (MAX(salary)) for each group defined by theGROUPBYclause(department_id), and aggregates the results again.
In the list ofaggregate functions that follows, functions followed by an asterisk (*) allowthewindowing_clause.
--聚合函数的列表如下,加星号的可以使用开窗子句,具体每个聚合函数的用法参考官方文档。
AVG
COLLECT
CORR
CORR_*
COUNT
COVAR_POP
COVAR_SAMP
CUME_DIST
DENSE_RANK
FIRST
GROUP_ID
GROUPING
GROUPING_ID
LAST
LISTAGG
MAX
MEDIAN
MIN
PERCENT_RANK
PERCENTILE_CONT
PERCENTILE_DISC
RANK
REGR_(Linear Regression) Functions
STATS_BINOMIAL_TEST
STATS_CROSSTAB
STATS_F_TEST
STATS_KS_TEST
STATS_MODE
STATS_MW_TEST
STATS_ONE_WAY_ANOVA
STATS_T_TEST_*
STATS_WSR_TEST
STDDEV
STDDEV_POP
STDDEV_SAMP
SUM
SYS_XMLAGG
VAR_POP
VAR_SAMP
VARIANCE
XMLAGG
-------------------------------------------------------------------------------------------------------
版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!
Blog: http://blog.csdn.net/tianlesoftware
Weibo: http://weibo.com/tianlesoftware
Email: tianlesoftware@gmail.com
Skype: tianlesoftware
-------加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请----
DBA1 群:62697716(满); DBA2 群:62697977(满)DBA3 群:62697850(满)
DBA 超级群:63306533(满); DBA4 群:83829929 DBA5群: 142216823
DBA6 群:158654907 DBA7 群:172855474 DBA8群:102954821
分享到:
相关推荐
聚合函数(Aggregate Functions)根据行组而不是单行进行计算,并返回单个结果行,即Oracle将聚合函数应用于每组行,且每组行只执行一次计算并返回一个结果行。 聚合函数可以出现在SELECT列表中,也可以出现在ORDER ...
aggregate_functions聚合函数.sql
2聚合感知函数@Aggregate_Aware1聚合感知函数@Aggregate_Aware1聚合感知函数@Aggregate_Aware
mongo聚合函数(aggregate)java版, 类似mysql的group。 对应查询语句可查看 https://blog.csdn.net/xu180/article/details/89175663
1聚合感知函数@Aggregate_Aware1聚合感知函数@Aggregate_Aware1聚合感知函数@Aggregate_Aware1聚合感知函数@Aggregate_Aware
字符串拼接 聚合函数.rar
主要介绍了django的聚合函数和aggregate、annotate方法使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
GROUP BY 用于结合聚合函数,根据一个或多个列对结果集进行分组。 HAVING 让我们筛选分组后的各组数据。 EXISTS 用于判断查询子句是否有记录,如果有一条或多条记录存在返回 True,否则返回 False。 UCASE()把字段...
第一章 整体介绍 2 1.1 什么是 Table API 和 Flink SQL 2 1.2 需要引入的依赖 2 1.3 两种 planner(old & blink)的区别 4 第二章 API 调用 5 ...5.2.5 表聚合函数(Table Aggregate Functions) 47
主要介绍了C#中累加器函数Aggregate用法,实例分析了C#中累加器的实现与使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下
PGWinFunc: Optimizing Window Aggregate Functions in PostgreSQL and its application for trajectory data
一、聚合 aggregate 聚合(aggregate)主要用于计算数据,类似sql中的sum()、avg() 语法: db.集合名称.aggregate([{管道:{表达式}}]) 管道:管道在Unix和Linux中一般用于将当前命令的输出结果作为下一个命令的输入,...
meteor-aggregate, 对 Meteor的适当的MongoDB聚合支持 meteorhacks:aggregate为 Meteor 添加适当聚合支持的简单软件包。 这个包在 Mongo.Collection 实例上公开了 .aggregate 方法。这只在服务器端工作,没有...
本文实例讲述了jQuery聚合函数。分享给大家供大家参考。具体如下: (function($) { $.fn.aggregate = function(seed, func) { var _r = seed == null ? : seed; this.each(function(index, element) { _r = ...
matlab开发-aggregate。基于对另一个矩阵中的变量进行分组,对一个矩阵中的值进行分组(并对其应用函数)
每一轮的迭代,服务端会从当前的客户端集合中随机挑选一部分参与本轮迭代训练,被选中的客户端调用本地训练接口local_train进行本地训练,最后服务端调用模型聚合函数model_aggregate来更新全局模型。
mongodb group aggregate项目实战笔记 管道聚合 mongodb group按时间分组,用aggregate管道聚合 会比group的处理效率要高而且更灵活方便
5.2聚集函数Aggregate Functions 5.3字符函数char Functions 5.4日期函数Date Functions 5.5数学函数Math Functions 5.6分析函数Analytical Functions /*********************************************************/...