我想编写一个带有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
我想编写一个带有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
用这种方式试一试:
SELECT
services.id,
CASE WHEN services.description LIKE '%-'
THEN services.amount * -1
ELSE services.amount
END) AS service_amount
FROM services