WHEN type=1 THEN payable_price WHEN type=2 THEN payable_price ELSE MAX(payable_price)
type=1 表示订单维度,type=2表示商品维度,需要无论type值为多少都取type=1时的payable_price值
解决方案:
使用SQL子查询;
SELECT
CASE
WHEN type = 1 THEN payable_price
WHEN type = 2 THEN (SELECT payable_price FROM your_table WHERE type = 1 LIMIT 1)
ELSE (SELECT MAX(payable_price) FROM your_table)
END AS amount
FROM your_table;