Invantive 문서Invantive Cloud의 일부
Invantive 지원 포럼로그인 / 회원가입

Max 집계 함수

구문

%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart LR
    maxAggregateFunction_start((START))
    maxAggregateFunction_start --> maxAggregateFunction_0_0[MAX]:::quoted
    maxAggregateFunction_0_0 --> maxAggregateFunction_0_1["("]:::quoted
    maxAggregateFunction_0_1 --> maxAggregateFunction_0_2[<a href="Invantive UniversalSQL/Grammar/Expression" class="internal-link">expression</a>]
    maxAggregateFunction_0_1 --> maxAggregateFunction_0_1a[DISTINCT]:::quoted
    maxAggregateFunction_0_1 --> maxAggregateFunction_0_1b[ALL]:::quoted
    maxAggregateFunction_0_1a --> maxAggregateFunction_0_2
    maxAggregateFunction_0_1b --> maxAggregateFunction_0_2
    maxAggregateFunction_0_2 --> maxAggregateFunction_0_3[")"]:::quoted
    maxAggregateFunction_0_3 --> maxAggregateFunction_end((END))

목적

숫자 값 또는 텍스트 값으로 이루어진 그룹에서 최댓값을 찾는 그룹 함수입니다. null 값은 무시되며, 모든 값이 null인 경우 결과는 null입니다. 텍스트는 각 문자의 코드값(순서 기준)으로 비교되며, order by에서와 같이 'a'와 'B'의 최댓값은 'a'입니다. 릴리스 27.0까지는 텍스트가 컴퓨터의 언어 설정에 따라 비교되었습니다. 한 행 내에서 여러 값 중 가장 큰 값을 찾으려면 다음을 사용하십시오: GREATEST. 릴리스 28.0부터 DISTINCT 및 ALL 키워드가 허용되며, 결과는 변하지 않습니다.

예시

다음 예제는 고객 5명으로 구성된 고객 기반에서 가장 높은 신용 한도를 조회합니다:

select max(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

-------------------
50000

다음 예제는 고객 세그먼트별로 가장 높은 미결 잔액을 조회합니다. 유일한 Services 고객의 잔액은 null이므로 해당 세그먼트의 결과는 비어 있습니다:

select cus.segment
,      max(cus.balance)
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    12500
Services
Wholesale        7500