Min Aggregate Function
Syntax
%%{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))
Purpose
Group function to find the minimum value from a group of numerical values or text values. Occurrences of null are ignored; when solely null values are present, the outcome is null. Texts are compared by the code of each character (ordinal), as in order by, so the minimum of 'a' and 'B' is 'B'. Up to release 27.0 texts were compared by the language settings of the computer. To find the smallest of several values within one row, use LEAST. DISTINCT and ALL are accepted from release 28.0 and do not change the outcome.
Examples
The following example retrieves the lowest credit limit across a customer base of five customers:
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
The following example retrieves the lowest outstanding balance per customer segment; the balance of the sole Services customer is null, so the outcome for that segment is empty:
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