-1

How would I do the pivot below?

I have a table like this:

+------+---+----+
| round| id| kpi|
+------+---+----+
| 0    | 1 | 0.1|
| 1    | 1 | 0.2|
| 0    | 2 | 0.5|
| 1    | 2 | 0.4|
+------+---+----+

I want to convert the id column into multiple columns (same amount of different ids), with KPI value as their values and in the new table we keep the rounds like in the first table.

+------+----+----+
| round| id1| id2|
+------+----+----+
| 0    | 0.1| 0.5|
| 1    | 0.2| 0.4|
+------+----+----+

Is it possible to do this in SQL? How to do that?

Thaise
  • 1,043
  • 3
  • 16
  • 28

1 Answers1

0

You are looking for a pivot function. You can find details on how to do this here and here. The first link also provides input into how to do this if you have an unknown number of columnnames.

AlexanderP
  • 126
  • 6