How to transform SELECT output column to arbitrary value based on this column?

user606521

For now I have following query:

SELECT "type" AS "modifiedType"
FROM "Table" 
WHERE "type" = 'type1' OR "type" = 'type2'

What I want is to return modifiedType like this:

if "type" = 'type1' then 'modifiedType1'
else if "type" = 'type2' then 'modifiedType2'

So I just want to modify column value with another value based on original column value. Type column in ENUM not string.

I am using Postgres 9.3 (or 9.4?).

a_horse_with_no_name

Use a CASE statement:

select type,
       case
         when type = 'type1' then 'modifiedType1'
         when type = 'type2' then 'modifiedType2'
         else type
       end as modifiedType
from the_table
WHERE type in ('type1', 'type2')

Btw: type is not a good name for a column

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to transform SELECT output column to arbitrary value based on this column?

From Java

'IF' in 'SELECT' statement - choose output value based on column values

From Dev

How to select boolean column based on the other column value in SQL?

From Dev

SELECT with temporary column with value based on other column

From Dev

SELECT with temporary column with value based on other column

From Dev

Select lines based on value in a column

From Dev

Conditional select based on column value

From Dev

Select lines based on value in a column

From Dev

How to select a bit based on value in another tables column in SQL

From Dev

How to select a column value based on two row conditions?

From Dev

How to Select a column based on string

From Dev

How to select a value from a column which is based on other row and column value?

From Dev

MySQL first select column based on parameter value and then value of column

From Dev

MySQL first select column based on parameter value and then value of column

From Dev

Importing data using ImportJSON to Google Sheets, select value output based on column name?

From Dev

If duplicates exist, select the value based on another column

From Dev

Select new column based on existing value

From Dev

MySQL, select column name based on a value

From Dev

Select all the rows based on a column value pandas

From Dev

mysql select query php based on column value

From Dev

Sql select query based on a column value

From Dev

Select rows based on value in specific column

From Dev

Oracle Select Query based on Column value

From Dev

Select a checkbox based on a column value using XPath

From Dev

Select all the rows based on a column value pandas

From Dev

how to select rows with max value based on one column and group by second column using awk?

From Dev

python pandas dataframe transform based on tag/column value

From Dev

SELECT Mysql - Replacing value in one column based on another column

From Dev

SQL Server - Select column to update based on another column value

Related Related

  1. 1

    How to transform SELECT output column to arbitrary value based on this column?

  2. 2

    'IF' in 'SELECT' statement - choose output value based on column values

  3. 3

    How to select boolean column based on the other column value in SQL?

  4. 4

    SELECT with temporary column with value based on other column

  5. 5

    SELECT with temporary column with value based on other column

  6. 6

    Select lines based on value in a column

  7. 7

    Conditional select based on column value

  8. 8

    Select lines based on value in a column

  9. 9

    How to select a bit based on value in another tables column in SQL

  10. 10

    How to select a column value based on two row conditions?

  11. 11

    How to Select a column based on string

  12. 12

    How to select a value from a column which is based on other row and column value?

  13. 13

    MySQL first select column based on parameter value and then value of column

  14. 14

    MySQL first select column based on parameter value and then value of column

  15. 15

    Importing data using ImportJSON to Google Sheets, select value output based on column name?

  16. 16

    If duplicates exist, select the value based on another column

  17. 17

    Select new column based on existing value

  18. 18

    MySQL, select column name based on a value

  19. 19

    Select all the rows based on a column value pandas

  20. 20

    mysql select query php based on column value

  21. 21

    Sql select query based on a column value

  22. 22

    Select rows based on value in specific column

  23. 23

    Oracle Select Query based on Column value

  24. 24

    Select a checkbox based on a column value using XPath

  25. 25

    Select all the rows based on a column value pandas

  26. 26

    how to select rows with max value based on one column and group by second column using awk?

  27. 27

    python pandas dataframe transform based on tag/column value

  28. 28

    SELECT Mysql - Replacing value in one column based on another column

  29. 29

    SQL Server - Select column to update based on another column value

HotTag

Archive