开发者

SQL : Pivot a two text columns table?

开发者 https://www.devze.com 2023-04-05 06:17 出处:网络
I\'m new to SQL and the Pivot function. I want to pivot the following table: namevalue ----------开发者_StackOverflow中文版

I'm new to SQL and the Pivot function. I want to pivot the following table:

name   value
-----  -----开发者_StackOverflow中文版
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 nameX columns manually, so if you want to pivot for unlimited/unknown number of columns, you'll have to dynamically construct the SQL clause.

0

精彩评论

暂无评论...
验证码 换一张
取 消