Home > Software design >  how to move data from one column to another column's row in postgres?
how to move data from one column to another column's row in postgres?

Time:06-21

How I start coding to get below output.

id Column1
1 A1
2 A2
3 A1
4 A2
5 A1
6 A1

output should be below.

id Column1 Column1.1 Column1.2
1 A1 A1
2 A2 A2
3 A1 A1
4 A2 A2
5 A1 A1
6 A1 A1

CodePudding user response:

We can try to use CASE WHEN expression to make it.

SELECT id,
       Column1,
       CASE WHEN Column1 = 'A1' THEN Column1 END 'Column1.1',
       CASE WHEN Column1 = 'A2' THEN Column1 END 'Column1.2'
FROM T
  • Related