sahil
sahil

Reputation: 121

how to move data from one column to another column's row in postgres?

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

Upvotes: 0

Views: 129

Answers (1)

D-Shih
D-Shih

Reputation: 46239

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

Upvotes: 1

Related Questions