Skip to main content
Returns the value of x associated with the minimum value of y. For example, SELECT min_by(subject, exam_result) FROM exam; is to return the subject that has the lowest exam score. This function is supported from v2.5.

Syntax

Parameters

  • x: an expression of any type.
  • y: an expression of a type that can be ordered.

Return value

Returns a value that has the same type as x.

Usage notes

  • y must be a sortable type. If you use an unsortable type of y, such as bitmap or hll, an error is returned.
  • If y contains a null value, the row that corresponds to the null value is ignored.
  • If more than one value of x has the same minimum value of y, this function returns the first value of x encountered.

Examples

  1. Create a table exam.
  2. Insert values into this table and query data from this table.
  3. Obtain the subject that has the lowest score. The subject english that has the lowest score 70 is returned.