"Oracle Database Programming Guide" 15-05: Nested aggregate functions

Cover: scan two-dimensional code figure concerns courses

Content navigation

1. Definitions

One-way function can be nested or nested, and the nesting function can only two packets.

2, Grammar

Packet format is the following three kinds of functions:

  • G1(Group_item) = Result
    如SUM(Group_item),AVG(Group_item)
  • G1(G2(Group_item)) = Result
    如SUM(AVG(Group_item))
  • G1 (G2 (G3 (Group_item) )) = Result
    Note, this particular format is not allowed. The MAX (SUM (AVG (Group_item) )) Note that the function can not be applied to a single value of the packet, this would be written in a final value Max selecting the maximum value.

3, Code

/*
作者:AT阿宝哥
日期:2016年9月18日
愿景:参考官方资料,做最好的课程,成就更多职业人!
邮箱:[email protected]
CSDN:https://blog.csdn.net/goldentec
简书:https://www.jianshu.com/u/8a6075d7a2e0
说明:

注意:
    
*/
-------------------------------------------------------------------------------
--Sample1:    
SELECT sum(comm) ,nvl(deptno,0)
          FROM emp
          WHERE nvl(deptno,0) IN (40,80,0)
          Group  by deptno;


SELECT avg( sum(  comm  ) )
          from emp
          where nvl(deptno,0) IN (40,80,0)
          Group  by deptno;
-------------------------------------------------------------------------------
--Sample2:错误,分组函数的嵌套太深.
select count(SUM(avg(sal)))  from  emp;  --group function is nested too deeply

-------------------------------------------------------------------------------
--Sample3:在分组函数中可以嵌套单行函数.

select SUM( avg(  length(ename) )  )  from  emp  group  by deptno;

-------------------------------------------------------------------------------

Published 65 original articles · won praise 167 · views 20000 +

Guess you like

Origin blog.csdn.net/goldentec/article/details/104875200