snowflake.snowpark.functions.min_by¶
- snowflake.snowpark.functions.min_by(col_to_return: Union[Column, str], col_containing_minimum: Union[Column, str], maximum_number_of_values_to_return: Optional[int] = None) Column [source]¶
Finds the row(s) containing the minimum value for a column and returns the value of another column in that row.
Example:
>>> df = session.create_dataframe([ ... [1001, 10, 10000], ... [1020, 10, 9000], ... [1030, 10, 8000], ... [900, 20, 15000], ... [2000, 20, None], ... [2010, 20, 15000], ... [2020, 20, 8000] ... ], schema=["employee_id", "department_id", "salary"]) >>> df.select(min_by("employee_id", "salary", 3).alias("min_by")).collect() [Row(MIN_BY='[\n 1030,\n 2020,\n 1020\n]')]