Hitachi

Hitachi Advanced Database SQL Reference


7.23.5 MIN

MIN determines the minimum value.

Organization of this subsection

(1) Specification format

general-set-function-MIN ::= {MIN([ALL] value-expression)|MIN(DISTINCT value-expression)}

Note: Whichever form is specified, the results will be the same.

(2) Explanation of specification format

MIN([ALL] value-expression):

Determines the minimum value of the result of the value expression. For details about value expressions, see 7.21 Value expression.

ALL can be omitted. The results will be the same regardless of whether it is specified.

MIN(DISTINCT value-expression):

Determines the minimum value of the results of the value expression. For details about value expressions, see 7.21 Value expression.

(3) Rules

  1. Null values are not included in the calculation.

  2. In the following cases, the execution result will be a null value:

    • If the number of input rows is 0

    • If the values to be calculated are all null values

  3. The following table shows the data type that can be specified in the value expression and the data type of the execution result of the general set function MIN.

    Table 7‒25: Relationship between data type that can be specified in the value expression and data type of the execution result of the general set function MIN

    No.

    Data type that can be specified in the value expression

    Data type of the execution result of general set function MIN

    1

    BIGINT

    BIGINT#

    2

    INTEGER

    INTEGER

    3

    SMALLINT

    SMALLINT

    4

    DECIMAL(m,n)

    DECIMAL(m,n)

    5

    NUMERIC(m,n)

    6

    DOUBLE PRECISION

    DOUBLE PRECISION

    7

    FLOAT

    8

    REAL

    REAL

    9

    CHARACTER(n)

    CHARACTER(n)

    10

    VARCHAR(n)

    VARCHAR(n)

    11

    STRING

    STRING

    12

    DATE

    DATE

    13

    TIME(p)

    TIME(p)

    14

    TIMESTAMP(p) WITHOUT TIME ZONE

    TIMESTAMP(p) WITHOUT TIME ZONE

    15

    TIMESTAMP(p) WITH TIME ZONE

    TIMESTAMP(p) WITH TIME ZONE

    16

    BOOLEAN

    BOOLEAN

    #

    If the data format of the integer data type is a legacy format, the data type of the execution result will be an INTEGER type.

(4) Examples

Example 1

Using the data in the employee table (EMPLIST), this example determines the age (AGE) of the youngest female employee.

SELECT MIN("AGE") AS "MIN-AGE"
    FROM "EMPLIST"
       WHERE "SEX"='F'

Example of execution results

[Figure]

Example 2

Using the data in the employee table (EMPLIST), this example determines the age (AGE) of the youngest employee in each section (SCODE).

SELECT "SCODE",MIN("AGE") AS "MIN-AGE"
    FROM "EMPLIST"
        GROUP BY "SCODE"

Example of execution results

[Figure]

Example 3

Using the data in the employee table (EMPLIST), this example determines the ages (AGE) of the oldest employee and the youngest employee in each section where the age difference does not exceed 20 years.

SELECT "SCODE",MAX("AGE") AS "MAX-AGE",MIN("AGE") AS "MIN-AGE"
    FROM "EMPLIST"
        GROUP BY "SCODE"
        HAVING MAX("AGE")-MIN("AGE")<=20

Example of execution results

[Figure]