【问题标题】:Unpivot, pivot and Count values in BigqueryBigquery 中的 Unpivot、pivot 和 Count 值
【发布时间】:2021-06-13 07:32:40
【问题描述】:

我正在尝试计算所有不同的 answerTypes,同时进行数据透视和反透视以将 QuestionNumber 作为不同的行值。

我不知道如何将所有这些组合到 BigQuery 中的单个查询中以获得该输出。

【问题讨论】:

    标签: sql google-bigquery


    【解决方案1】:

    一种方法是:

    select question,
           countif(q = 'Good') as good,
           countif(q = 'Bad') as bad,
           countif(q = 'N/A') as n_a
    from ((select '1A' as question, question1a  as q from t) union all
          (select '1B' as question, question1b from t) union all
          (select '1C' as question, question1c from t)
         ) x
    group by question;
    

    有一些更好的方法可以取消透视数据,但这似乎可以捕捉到您想要做的事情。

    【讨论】:

      猜你喜欢
      • 2022-10-04
      • 2016-02-21
      • 2019-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      相关资源
      最近更新 更多