user8545255
user8545255

Reputation: 849

Create a new column based on values of other columns in postgres

What i have

customer_id
   1
   2 
   2
   1
   3

What i want (for all customer id's with 1 ,i want to flag as valid ,rest of the customer id's as invalid in the new column "warining_customer_id"

customer_id    warining_customer_id
   1             Valid
   2             Invalid
   2             Invalid
   1             Valid
   3             Invalid

Upvotes: 1

Views: 1398

Answers (1)

Mihawk
Mihawk

Reputation: 835

Here an example

SELECT   customer.customer_id AS customer_id,
         CASE WHEN customer.customer_id = 1 THEN 'Valid' ELSE 'Invalid' END
             AS warning_customer_id
  FROM   (SELECT   1 AS customer_id FROM DUAL
          UNION ALL
          SELECT   2 AS customer_id FROM DUAL) customer

Upvotes: 1

Related Questions