我想编写一个带有CASE WHEN子句的SQL语句,该子句使用LIKE运算符,但我不确定如何正确格式化该语句。
SELECT
services.id,
(CASE services.description
WHEN LIKE '%-'
THEN services.amount * -1
ELSE services.amount
END) AS service_amount
FROM services
答案 0 :(得分:5)
以这种方式尝试:
SELECT
services.id,
CASE WHEN services.description LIKE '%-'
THEN services.amount * -1
ELSE services.amount
END) AS service_amount
FROM services