BigQuery当前活动查询仅返回一个app_id

时间:2017-04-11 18:39:15

标签: sql google-bigquery

我正在使用以下查询来查询项目中的多个表和数据集。前两个union all工作正常并将返回我想要的,我遇到的问题是,当添加更多时,它不会向输出添加任何其他内容。我认为这来自我GROUP BY,但我不确定。任何帮助都会很棒。

预期结果应该是多个目标,而不仅仅是一个。

WITH allTables AS (
SELECT 
   CONCAT(user_dim.app_info.app_id, ':', user_dim.app_info.app_platform) as app,
   user_dim.app_info.app_instance_id AS users
 FROM `d1.app_events_intraday_*`, UNNEST(event_dim) AS event
 WHERE _TABLE_SUFFIX 
  BETWEEN '20170406' AND '20170406'

 UNION ALL
 SELECT 
   CONCAT(user_dim.app_info.app_id, ':', user_dim.app_info.app_platform) as app,
   user_dim.app_info.app_instance_id AS users
 FROM `d1.app_events_*`, UNNEST(event_dim) AS event
 WHERE _TABLE_SUFFIX 
  BETWEEN '20170406' AND '20170406'

   UNION ALL
    SELECT 
     CONCAT(user_dim.app_info.app_id, ':', user_dim.app_info.app_platform) as app,
     user_dim.app_info.app_instance_id AS users
   FROM `d2.app_events_intraday_*`, UNNEST(event_dim) AS event
   WHERE _TABLE_SUFFIX 
    BETWEEN '20170406' AND '20170406'

   UNION ALL
   SELECT 
     CONCAT(user_dim.app_info.app_id, ':', user_dim.app_info.app_platform) as app,
     user_dim.app_info.app_instance_id AS users
   FROM `d2.app_events_*`, UNNEST(event_dim) AS event
   WHERE _TABLE_SUFFIX 
    BETWEEN '20170406' AND '20170406'
) SELECT 
   app as target,
   COUNT(DISTINCT(users)) AS datapoint_value,
   UNIX_SECONDS(PARSE_TIMESTAMP('%Y%m%d', '20170406')) as datapoint_time
 FROM allTables
 GROUP BY app

1 个答案:

答案 0 :(得分:2)

分别运行查询的最后一部分:

  SELECT 
  CONCAT(user_dim.app_info.app_id, ':', user_dim.app_info.app_platform) as 
    app,
          user_dim.app_info.app_instance_id AS users
          FROM `d2.app_events_*`, UNNEST(event_dim) AS event
            WHERE _TABLE_SUFFIX 
             BETWEEN '20170406' AND '20170406'