# min, mins, mmin

Minimum/s

## min

Minimum

Syntax: min x, min[x]

Where x is a sortable list, returns its minimum. The minimum of an atom is itself. Applies to any datatype except symbol. Nulls are ignored, except that if the argument has only nulls, the result is infinity.

q)min 2 5 7 1 3
1
q)min "genie"
"e"
q)min 0N 5 0N 1 3                  / nulls are ignored
1
q)min 0N 0N                        / infinity if all null
0W
q)select min price by sym from t   / use in a select statement


min is an aggregate function.

## mins

Minimums

Syntax: mins x, mins[x]

Where x is a sortable list, returns the running minimums of the prefixes. The minimum of an atom is itself. Applies to any datatype except symbol. Nulls are ignored, except that initial nulls are returned as infinity.

q)mins 2 5 7 1 3
2 2 2 1 1
q)mins "genie"
"geeee"
q)mins 0N 5 0N 1 3         / initial nulls return infinity
0W 5 5 1 1


mins is a uniform function.

## mmin

Moving minimums

Syntax: x mmin y, mmin[x;y]

Where

• x is a positive int atom
• y is a numeric list

returns the x-item moving minimums of y, with nulls treated as the minimum value. The first x items of the result are the minimums of the terms so far, and thereafter the result is the moving minimum.

q)3 mmin 0N -3 -2 1 -0W 0
0N 0N 0N -3 -0W -0W
q)3 mmin 0N -3 -2 1 0N -0W    / null is the minimum value
0N 0N 0N -3 0N 0N


mmin is a uniform function.

Knowledge Base: Sliding windows
Basics: Mathematics

## Aggregating nulls

avg, min, max and sum are special: they ignore nulls, in order to be similar to SQL92. But for nested x these functions preserve the nulls.

q)min (1 2;0N 4)
0N 2