IF
Returns one value if a logical expression is TRUE and another if it is FALSE.
Syntax
IF(<condition>, <then>, <else>)
Parameter | Type | Description |
---|---|---|
condition | Boolean | An expression that returns logical value, i.e. TRUE or FALSE. |
then | any | The value the function returns if condition is TRUE. |
else | any | The value the function returns if condition is FALSE. |
Return values
Depends on input arguments.
Examples
IF(orders.country == "US", "United States", "Other")
IF(products.qty > 0, "in stock", "out of stock")
IF(
AND(customers.orders > 10, DATEDIFF(customers.last_order_at, NOW(), DAY) < 10),
"Loyal",
IF(
DATEDIFF(customers.last_order_at, NOW(), DAY) > 50),
"Dormant",
"New"
)
)