This is also not with the rotation axis, but in case you need to group elements into groups of 3 ordered by identifier, and the identifier has spaces, for example, sometimes this happens, this should do it:
select
ROW,
max(case when COL = 0 then Code end) as Code1,
max(case when COL = 0 then Value end) as Value1,
max(case when COL = 1 then Code end) as Code2,
max(case when COL = 1 then Value end) as Value2,
max(case when COL = 2 then Code end) as Code3,
max(case when COL = 2 then Value end) as Value3
FROM (
select
(row_number() over (order by ID)-1) % 3 as COL,
(row_number() over (order by ID)-1) / 3 as ROW,
Code,
Value
from
data
) X
group by ROW
This calculates the number of rows and columns based on row_number that increment by identifier, and then uses the group to break the results into groups of 3.
SQL Fiddle
source
share