I have a table with column headers like this:
p_id|s_id|value
So the table is like:
1|1|39
1|2|97
1|3|42
the first column is p_id
, second is s_id
, third is value
.
There are 673 or so distinct values for p_id
, there are about six possible values for s_id
, and value
is an integer.
Each (p_id
, s_id
) pair maps to a value
, and there are six of these values for each p_id
(because there are only six possible s_id
's).
Here are some examples:
(p_id, s_id, value)
(1, 1, 238), (1, 2, 489), ... (1, 6, 391),
(2, 1, 380), (2, 2, 112), ... (2, 6, 402),
. . .
(673, 1, 371), (673, 2, 239), ... (673, 6, 230)
So here's what I want as column headers for what I'm trying to get as output:
p_id 1 2 3 4 5 6
And then the table would be populated with the "value"s.
How do I do this with SQL statements? Do I need to make a new table?