【问题标题】:Unable to Unpivot in MS Sql Server无法在 MS Sql Server 中取消透视
【发布时间】:2021-12-25 05:29:04
【问题描述】:

我无法取消透视此表。我不断收到两个表不存在的错误。我正在使用 Microsoft SQL Server Management Studio。以下是错误。

type            Small_Bags         Large_Bags
conventional    8603.6201171875     93.25
conventional    9408.0703125        97.4899978637695
conventional    8042.2099609375     103.139999389648
conventional    5677.39990234375    133.759994506836
conventional    5986.259765625      197.690002441406
conventional    6556.47021484375    127.440002441406

消息 207,第 16 级,状态 1,第 74 行 列名“Small_Bags”无效。 消息 207,第 16 层,状态 1,第 74 行 列名“Large_Bags”无效

select type,Small_Bags,Large_Bags from avocado
unpivot
(
    amount 
    for category in (Small_Bags,Large_Bags)
) as unpivotexample

【问题讨论】:

  • 1. MS-SQL 还是 MySQL? - 请标记正确的 DBMS 2. 请提供示例输入数据和预期输出。

标签: sql sql-server pivot unpivot


【解决方案1】:

Microsoft SQL Server Management Studio 意味着我相信 SQL Server。您的数据透视表将 Small_Bags,Large_Bags 列转换为 category, amount 列。所以

select type, category, amount 
from avocado
unpivot
(
    amount 
    for category in (Small_Bags,Large_Bags)
) as unpivotexample

db<>fiddle

【讨论】:

    猜你喜欢
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    相关资源
    最近更新 更多