ARG_MAX (Lakehouse v1)
Calculates the arg value for a maximum val value. If there are several values of arg for maximum values of val, returns the first of these values encountered.
Analyze Syntax
Section titled “Analyze Syntax”func.arg_max(<expr>)Analyze Examples
Section titled “Analyze Examples”func.arg_max(table.product, table.price).alias('max_price_product')
| max_price_product || ----------------- || Product C |SQL Syntax
Section titled “SQL Syntax”ARG_MAX(<arg>, <val>)Arguments
Section titled “Arguments”| Arguments | Description |
|---|---|
<arg> | Argument of any data type that PlaidCloud Lakehouse supports |
<val> | Value of any data type that PlaidCloud Lakehouse supports |
Return Type
Section titled “Return Type”arg value that corresponds to maximum val value.
matches arg type.
SQL Examples
Section titled “SQL Examples”Creating a Table and Inserting Sample Data
Let’s create a table named “sales” and insert some sample data:
CREATE TABLE sales ( id INTEGER, product VARCHAR(50), price FLOAT);
INSERT INTO sales (id, product, price)VALUES (1, 'Product A', 10.5), (2, 'Product B', 20.75), (3, 'Product C', 30.0), (4, 'Product D', 15.25), (5, 'Product E', 25.5);Query: Using ARG_MAX() Function
Now, let’s use the ARG_MAX() function to find the product that has the maximum price:
SELECT ARG_MAX(product, price) AS max_price_productFROM sales;The result should look like this:
| max_price_product || ----------------- || Product C |