I’m new to SQL and the Pivot function.
I want to pivot the following table:
name value
----- -----
name1 value1
name2 value2
name3 value3
To:
name1 name2 name3
------ ------ ------
value1 value2 value3
Any idea how I can do it? Because when I read about the pivot function it required an accumulation function, but I want to keep it as strings.
You can use a bogus aggregate function applicable to strings, such as
MIN.But you have to list the
nameXcolumns manually, so if you want to pivot for unlimited/unknown number of columns, you’ll have to dynamically construct the SQL clause.