maxcompute case when
时间: 2023-10-26 20:49:11 浏览: 80
The "CASE WHEN" statement in MaxCompute is a conditional expression used to evaluate multiple conditions and return different values based on the conditions met.
The syntax for the "CASE WHEN" statement is as follows:
CASE WHEN condition1 THEN value1
WHEN condition2 THEN value2
...
ELSE default_value
END
The "condition" part of the statement can be any valid expression that evaluates to true or false. If the condition is true, then the corresponding "value" is returned. If none of the conditions are true, then the "default_value" is returned.
For example, suppose you have a table of customer orders with columns "order_id", "customer_id", and "order_total". You could use a "CASE WHEN" statement to categorize the orders into different price ranges:
SELECT order_id, customer_id, order_total,
CASE WHEN order_total < 100 THEN 'Low'
WHEN order_total >= 100 AND order_total < 500 THEN 'Medium'
WHEN order_total >= 500 AND order_total < 1000 THEN 'High'
ELSE 'Very High'
END AS price_range
FROM orders;
This statement would return a result set with an additional column "price_range" that categorizes each order into a price range based on the "order_total" column.
阅读全文