[英]SQL : Pivot a two text columns table?
I'm new to SQL and the Pivot function. 我是SQL和Pivot函数的新手。 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
. 您可以使用适用于字符串的伪聚合函数,例如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. 但是您必须手动列出nameX
列,因此如果要为无限/未知数量的列进行透视,则必须动态构造SQL子句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.