Invantive-Dokumentation
Invantive SupportforenAnmelden / Eintragen

Aggregatfunktion First

Syntax

%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart TD
    firstAggregateFunction_start((START))
    firstAggregateFunction_start --> firstAggregateFunction_0_0[FIRST]:::quoted
    firstAggregateFunction_0_0 --> firstAggregateFunction_0_1["("]:::quoted
    firstAggregateFunction_0_1 --> firstAggregateFunction_0_2[<a href="Invantive UniversalSQL/Grammar/Expression" class="internal-link">expression</a>]
    firstAggregateFunction_0_2 --> firstAggregateFunction_0_3[")"]:::quoted
    firstAggregateFunction_0_3 --> firstAggregateFunction_end((END))

Anwendung

Gruppenfunktion zum ersten Nicht-null-Wert in einer sortierten Ergebnismenge. Die Reihenfolge der Zeilen wird durch die Quelle bestimmt; kombinieren Sie sie mit einer order by in einer verschachtelten Query, um ein deterministisches Ergebnis zu erhalten.

Beispiele

Das folgende Beispiel ruft die erste Kontaktperson aus einer Kontaktliste ab, in der Reihenfolge, in der die Kontakte gespeichert sind:

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

-------------------
Alice Johnson

Das folgende Beispiel ruft pro Kunde die alphabetisch erste Kontaktperson ab, beispielsweise als Standardadressat für einen Mahnbrief:

select srt.customer_name
,      first(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    Alice Johnson
Bergmann GmbH      Erika Weber
Carlson Ltd        James Smith
Dubois SA          Marie Dupont