【发布时间】:2021-06-13 07:32:40
【问题描述】:
我正在尝试计算所有不同的 answerTypes,同时进行数据透视和反透视以将 QuestionNumber 作为不同的行值。
我不知道如何将所有这些组合到 BigQuery 中的单个查询中以获得该输出。
【问题讨论】:
标签: sql google-bigquery
我正在尝试计算所有不同的 answerTypes,同时进行数据透视和反透视以将 QuestionNumber 作为不同的行值。
我不知道如何将所有这些组合到 BigQuery 中的单个查询中以获得该输出。
【问题讨论】:
标签: sql google-bigquery
一种方法是:
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;
有一些更好的方法可以取消透视数据,但这似乎可以捕捉到您想要做的事情。
【讨论】: