数据透视表列重命名
Posted
技术标签:
【中文标题】数据透视表列重命名【英文标题】:Pivot table column rename 【发布时间】:2021-02-08 04:25:58 【问题描述】:我正在尝试重命名 SQL Server 中的数据透视列,即
for days in ([22], [23], [24], [25], [26], [27], [28]
有没有办法做到这一点?
这是我的查询:
select *
from
(select
day(date) as days,
temp
from
temperature) as t
pivot
(max(temp)
for days in ([22], [23], [24], [25], [26], [27], [28])
) as pivot_table
【问题讨论】:
rename pivot columns
到底是什么意思?您是指结果中的列吗?
是的,我想将列从整数 22 重命名为二十二,从 23 重命名为二十三,依此类推。
SELECT [22] as [twenty-two], [23] as [twenty-three], . . .
【参考方案1】:
正如松鼠推荐的那样:
select [22] as [twenty-two], [23] as [twenty-three] ...
from (
select
day(date) as days,
temp
from temperature) as t
pivot(max(temp)
for days in ([22], [23], [24], [25], [26], [27], [28])
) as pivot_table
【讨论】:
以上是关于数据透视表列重命名的主要内容,如果未能解决你的问题,请参考以下文章