Google bigquery BigQuery-为什么我必须按所有列分组?

Google bigquery BigQuery-为什么我必须按所有列分组?,google-bigquery,Google Bigquery,以下查询的错误消息: SELECT sample_id, IF(PIK3CA_features = "chr3_3930069__TGT", 1, 0) AS chr3_3930069__TGT, IF(PIK3CA_features = "chr3_3929921_TC", 1, 0) AS chr3_3929921_TC, IF(PIK3CA_features = "chr3_3929739_TC", 1, 0) AS chr3_3929739_TC, IF(PIK3CA

以下查询的错误消息:

SELECT
  sample_id,
  IF(PIK3CA_features = "chr3_3930069__TGT", 1, 0) AS chr3_3930069__TGT,
  IF(PIK3CA_features = "chr3_3929921_TC", 1, 0) AS chr3_3929921_TC,
  IF(PIK3CA_features = "chr3_3929739_TC", 1, 0) AS chr3_3929739_TC,
  IF(PIK3CA_features = "chr3_3929813__T", 1, 0) AS chr3_3929813__T,
  IF(PIK3CA_features = "chr3_3929897_GA", 1, 0) AS chr3_3929897_GA,
  IF(PIK3CA_features = "chr3_3929843_TC", 1, 0) AS chr3_3929843_TC
FROM
  [pgp_PIK3CA_all_distinct_features_values]
GROUP BY
  sample_id
是:

错误:(L3:58):表达式“chr3_3930069___TGT”不存在于 按列表分组


如何仅按样本ID进行分组,以便在行中有唯一的样本ID,在列中有PIK3CA功能?

您没有按样本ID对所有列进行分组的聚合功能。您可以向其中添加max,这应该可以解决问题

SELECT
  sample_id,
  MAX(IF(PIK3CA_features = "chr3_3930069__TGT", 1, 0)) AS chr3_3930069__TGT,
  MAX(IF(PIK3CA_features = "chr3_3929921_TC", 1, 0)) AS chr3_3929921_TC,
  MAX(IF(PIK3CA_features = "chr3_3929739_TC", 1, 0)) AS chr3_3929739_TC,
  MAX(IF(PIK3CA_features = "chr3_3929813__T", 1, 0)) AS chr3_3929813__T,
  MAX(IF(PIK3CA_features = "chr3_3929897_GA", 1, 0)) AS chr3_3929897_GA,
  MAX(IF(PIK3CA_features = "chr3_3929843_TC", 1, 0)) AS chr3_3929843_TC
FROM
  [pgp_PIK3CA_all_distinct_features_values]
GROUP BY
  sample_id

您是否正在尝试获取
sample\u id
的每个表达式的计数?你能编辑你的帖子并添加预期的输出吗?