使用Google BigQuery的逗号作为UNION ALL和IN子句

时间:2016-02-13 21:46:57

标签: sql google-bigquery

我正在尝试执行以下查询:

SELECT 
  author, link_id, COUNT(link_id) as cnt
FROM 
  [fh-bigquery:reddit_comments.2015_12],
  [fh-bigquery:reddit_comments.2015_11]
WHERE link_id IN (
  SELECT posts.name
  FROM [fh-bigquery:reddit_posts.full_corpus_201512] AS posts
  WHERE posts.subreddit = 'politics'
  ORDER BY posts.created_utc DESC
  LIMIT 300
)
GROUP BY author, link_id
ORDER BY author

执行时收到此错误消息: JOIN(包括半连接)和UNION ALL(逗号,日期范围)可能不会合并到单个SELECT语句中。将UNION ALL移动到内部查询或将JOIN移动到外部查询。

删除其中一个comments表格工作正常但我似乎无法弄清楚BigQuery的Comma as UNION ALL如何运作。我试图将联合移动到内部查询但我仍然得到相同的错误。

1 个答案:

答案 0 :(得分:3)

错误在于我对将UNION ALL移动到内部查询的误解。解决了错误,我不得不将两个表放在基本的:invalid中。工作查询如下:

select * from ...