【问题标题】:How to create columns in SQL out of categorial rows如何在分类行之外的 SQL 中创建列
【发布时间】:2023-02-21 07:55:13
【问题描述】:

我正在处理一个 SQL 数据库,该数据库每月更新一次,其中附加了用户的账单信息。我想进行一些分析,但我需要将每月账单作为功能,因此作为列。这是当前表的示例: enter image description here

我希望它看起来像这样

enter image description here

【问题讨论】:

    标签: sql


    【解决方案1】:

    我想使用 CASE 创建列,但它会产生空值:

    
    select user_id,
           case when billing_month = 'jan23' then cat end
    from table
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-28
      • 2015-04-17
      • 2021-11-23
      • 1970-01-01
      • 2010-09-08
      • 1970-01-01
      相关资源
      最近更新 更多