如何在Postgres SQL的案例选择中使用like运算符?

时间:2017-05-04 18:00:45

标签: postgresql case

我想编写一个带有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

1 个答案:

答案 0 :(得分:5)

以这种方式尝试:

SELECT
   services.id,
   CASE WHEN services.description LIKE '%-'
        THEN services.amount * -1
        ELSE services.amount
   END) AS service_amount
 FROM services