Avg 집계 함수
구문
%%{init: {
'theme': 'base',
'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
'themeVariables': {
'fontSize': '11px',
'fontFamily': 'Arial'
}
}}%%
flowchart TD
avgAggregateFunction_start((START))
avgAggregateFunction_start --> avgAggregateFunction_0_0[AVG]:::quoted
avgAggregateFunction_0_0 --> avgAggregateFunction_0_1["("]:::quoted
avgAggregateFunction_0_1 --> avgAggregateFunction_0_3
avgAggregateFunction_0_1 --> avgAggregateFunction_0_2[DISTINCT]:::quoted
avgAggregateFunction_0_1 --> avgAggregateFunction_0_2a[ALL]:::quoted
avgAggregateFunction_0_2a --> avgAggregateFunction_0_3
avgAggregateFunction_0_2 --> avgAggregateFunction_0_3[<a href="Invantive UniversalSQL/General/Identifiers" class="internal-link">identifier</a>]
avgAggregateFunction_0_3 --> avgAggregateFunction_0_4[")"]:::quoted
avgAggregateFunction_0_4 --> avgAggregateFunction_end((END))
목적
숫자 값 그룹에서 평균값을 구하는 그룹 함수입니다. null 값의 발생은 무시됩니다. DISTINCT을(를) 지정하면 각 고유 값은 발생 횟수와 관계없이 한 번만 평균에 포함됩니다. ALL이(가) 기본값이며, 각 값은 발생한 횟수만큼 계산됩니다. ALL은(는) 릴리스 28.0부터 사용할 수 있습니다.
예시
다음 예제는 고객 5명으로 구성된 고객 기반에서 평균 신용 한도를 조회합니다:
select avg(cus.credit_limit)
from csvtable
( passing 'Acme Industries#Manufacturing#12500#50000|Bergmann GmbH#Manufacturing#0#25000|Carlson Ltd#Wholesale#2500#10000|Dubois SA#Wholesale#7500#10000|Everest BV#Services##5000'
row delimiter '|'
column delimiter '#'
columns name varchar2 position next
, segment varchar2 position next
, balance number position next
, credit_limit number position next
) cus
-------------------
20000
다음 예제는 고객 세그먼트별 평균 신용 한도를 조회합니다. 예를 들어 세그먼트 간 신용 위험 감수 성향을 비교할 때 사용할 수 있습니다:
select cus.segment
, avg(cus.credit_limit)
from csvtable
( passing 'Acme Industries#Manufacturing#12500#50000|Bergmann GmbH#Manufacturing#0#25000|Carlson Ltd#Wholesale#2500#10000|Dubois SA#Wholesale#7500#10000|Everest BV#Services##5000'
row delimiter '|'
column delimiter '#'
columns name varchar2 position next
, segment varchar2 position next
, balance number position next
, credit_limit number position next
) cus
group
by cus.segment
order
by cus.segment
-------------------
Manufacturing 37500
Services 5000
Wholesale 10000