【问题标题】: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], . . .

标签: sql sql-server tsql pivot


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-28
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多