使用 Google BigQuery 的逗号作为带有 IN 子句的 UNION ALL
Using Google BigQuery's Comma as UNION ALL with IN clause
我正在尝试执行以下查询:
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 是如何工作的。我试图将联合移动到内部查询,但我仍然遇到同样的错误。
错误是因为我误解了将 UNION ALL 移动到内部查询。为了解决错误,我不得不将两个表放在一个基本的 select * from ...
中。工作查询如下:
SELECT
author, link_id, COUNT(link_id) as cnt
FROM (
SELECT *
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
我正在尝试执行以下查询:
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 是如何工作的。我试图将联合移动到内部查询,但我仍然遇到同样的错误。
错误是因为我误解了将 UNION ALL 移动到内部查询。为了解决错误,我不得不将两个表放在一个基本的 select * from ...
中。工作查询如下:
SELECT
author, link_id, COUNT(link_id) as cnt
FROM (
SELECT *
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