Agregační funkce Min
Syntaxe
%%{init: {
'theme': 'base',
'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
'themeVariables': {
'fontSize': '11px',
'fontFamily': 'Arial'
}
}}%%
flowchart LR
minAggregateFunction_start((START))
minAggregateFunction_start --> minAggregateFunction_0_0[MIN]:::quoted
minAggregateFunction_0_0 --> minAggregateFunction_0_1["("]:::quoted
minAggregateFunction_0_1 --> minAggregateFunction_0_2[<a href="Invantive UniversalSQL/Grammar/Expression" class="internal-link">expression</a>]
minAggregateFunction_0_1 --> minAggregateFunction_0_1a[DISTINCT]:::quoted
minAggregateFunction_0_1 --> minAggregateFunction_0_1b[ALL]:::quoted
minAggregateFunction_0_1a --> minAggregateFunction_0_2
minAggregateFunction_0_1b --> minAggregateFunction_0_2
minAggregateFunction_0_2 --> minAggregateFunction_0_3[")"]:::quoted
minAggregateFunction_0_3 --> minAggregateFunction_end((END))
Účel
Skupinová funkce pro nalezení minimální hodnoty ze skupiny číselných hodnot nebo textových hodnot. Výskyty null jsou ignorovány; pokud jsou přítomny pouze hodnoty null, je výsledkem null. Texty se porovnávají podle kódu každého znaku (ordinálně), jako v order by, takže minimum z 'a' a 'B' je 'B'. Až do verze 27.0 byly texty porovnávány podle jazykového nastavení počítače. Chcete-li najít nejmenší z několika hodnot v rámci jednoho řádku, použijte LEAST. DISTINCT a ALL jsou podporovány od verze 28.0 a nemění výsledek.
Příklady
Následující příklad vrátí nejnižší úvěrový limit napříč základnou pěti zákazníků:
select min(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
-------------------
5000
Následující příklad vrátí nejnižší nesplacený zůstatek na segment zákazníků; zůstatek jediného zákazníka ze segmentu Services je null, takže výsledek pro tento segment je prázdný:
select cus.segment
, min(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 0
Services
Wholesale 2500