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

LAST 집계 함수

구문

%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart LR
    lastAggregateFunction_start((START))
    lastAggregateFunction_start --> lastAggregateFunction_0_0[LAST]:::quoted
    lastAggregateFunction_0_0 --> lastAggregateFunction_0_1["("]:::quoted
    lastAggregateFunction_0_1 --> lastAggregateFunction_0_2[<a href="Invantive UniversalSQL/Grammar/Expression" class="internal-link">expression</a>]
    lastAggregateFunction_0_2 --> lastAggregateFunction_0_3[")"]:::quoted
    lastAggregateFunction_0_3 --> lastAggregateFunction_end((END))

목적

정렬된 결과 집합에서 마지막 non-null 값을 구하는 그룹 함수입니다. 행의 순서는 소스에 의해 결정됩니다. 결정적인 결과를 얻으려면 중첩 쿼리에서 order by와 함께 사용하십시오.

예시

다음 예는 연락처 목록에서 연락처가 저장된 순서대로 마지막 담당자를 조회합니다.

select last(cnt.contact_name)
from   csvtable
       ( passing 'Acme Industries#Alice Johnson#CFO|Acme Industries#Tom Peters#Accounts Payable|Bergmann GmbH#Erika Weber#Controller|Carlson Ltd#James Smith#CFO|Dubois SA#Marie Dupont#Accounts Payable'
         row delimiter '|'
         column delimiter '#'
         columns customer_name varchar2 position next
         ,       contact_name  varchar2 position next
         ,       role          varchar2 position next
       ) cnt

-------------------
Marie Dupont

다음 예는 고객별로 알파벳 순서상 마지막 담당자를 조회합니다.

select srt.customer_name
,      last(srt.contact_name)
from   ( select cnt.customer_name
         ,      cnt.contact_name
         from   csvtable
                ( passing 'Acme Industries#Alice Johnson#CFO|Acme Industries#Tom Peters#Accounts Payable|Bergmann GmbH#Erika Weber#Controller|Carlson Ltd#James Smith#CFO|Dubois SA#Marie Dupont#Accounts Payable'
                  row delimiter '|'
                  column delimiter '#'
                  columns customer_name varchar2 position next
                  ,       contact_name  varchar2 position next
                  ,       role          varchar2 position next
                ) cnt
         order
         by     cnt.customer_name
         ,      cnt.contact_name
       ) srt
group
by     srt.customer_name
order
by     srt.customer_name

-------------------
Acme Industries    Tom Peters
Bergmann GmbH      Erika Weber
Carlson Ltd        James Smith
Dubois SA          Marie Dupont