设为首页 收藏本站
查看: 956|回复: 0

[经验分享] Oracle 聚合函数(Aggregate Functions)说明

[复制链接]

尚未签到

发表于 2016-7-22 08:43:57 | 显示全部楼层 |阅读模式
  
  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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-247581-1-1.html 上篇帖子: oracle三种复制技术之比较 下篇帖子: Oracle——01表空间和区
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表