0

I have a table with this structure and I need to recreate it as below, searched it before asking here but I couldn't find an answer as I expected. Could anyone help me which query should I use to get expected tables with PostgreSQL. Used exceljs npm package, but things become complicated

Source Table

ID NAME SLOT columnA columnB columnC columnD columnE
1 A SLOT1 300 3500 TRUE FALSE 50
2 B SLOT1 200 2500 TRUE TRUE 100
2 B SLOT2 300 3500 FALSE TRUE 100
3 C SLOT1 300 500 FALSE FALSE 150
2 B SLOT3 150 3500 TRUE TRUE 50
4 D SLOT1 150 3500 FALSE FALSE 0
4 D SLOT2 40 200 TRUE TRUE 200
4 D SLOT3 150 10000 FALSE TRUE 100
1 A SLOT2 50 450 FALSE FALSE 50
3 C SLOT2 80 280 TRUE TRUE 100

Expected Results

Restruct it by columnA

ID NAME SLOT1 SLOT2 SLOT3
1 A 300 50 NULL
2 B 200 300 150
3 C 300 80 NULL
4 D 150 40 150

Restruct it by columnB

ID NAME SLOT1 SLOT2 SLOT3
1 A 3500 450 NULL
2 B 2500 3500 3500
3 C 500 280 NULL
4 D 3500 200 10000

Restruct it by columnC

ID NAME SLOT1 SLOT2 SLOT3
1 A TRUE FALSE NULL
2 B TRUE FALSE TRUE
3 C FALSE TRUE NULL
4 D FALSE TRUE FALSE

Restruct it by columnD

ID NAME SLOT1 SLOT2 SLOT3
1 A FALSE FALSE NULL
2 B TRUE TRUE TRUE
3 C FALSE TRUE NULL
4 D FALSE TRUE FALSE

Restruct it by columnE

ID NAME SLOT1 SLOT2 SLOT3
1 A 50 50 NULL
2 B 100 100 50
3 C 150 100 NULL
4 D 0 200 100
Ahmet Zeybek
  • 1,196
  • 1
  • 13
  • 24

0 Answers0