输出不同的查询结果相同table

Output different query results in same table

最近更新后,google bigquery 现在允许从特定国家/地区的 tables 进行查询。我想查找美国的来源(网站)数量 table 包含单词 'space' 并将其与来自日本 table. 的类似结果并排显示 我正在进行的查询是 -

WITH
 query_1 as 
    (select distinct origin as japan 
     from `chrome-ux-report.country_jp.201712` where 
     origin like "%space%"),
 query_2 as 
    (select distinct origin as usa 
     from `chrome-ux-report.country_us.201712` 
     where origin like "%space%" )
SELECT japan,usa from query_1,query_2

但它会导致 table 在 japan 和 usa 列中多次重复相同的来源。另一个奇怪的事情是 o/p table 包含日本和美国相同数量的行,很明显,包含单词 'space' 的站点数量在 2 tables。我使用的是标准 sql,而不是旧版。 任何帮助表示赞赏。谢谢。
注意:并排,我的意思是会有两列,日本列显示日本的网站,美国列显示美国的结果。

在 BigQuery 标准中 SQL(您在查询中使用的)FROM 语句中表之间的逗号表示 CROSS JOIN。这就解释了为什么 it results in a table having multiple repetitions of the same origin in both the japan and usa column

取决于您希望结果看起来如何 - 您可以通过多种不同的方式构建查询 - 例如

WITH
 query_1 AS 
    (SELECT DISTINCT origin AS japan 
     FROM `chrome-ux-report.country_jp.201712` WHERE 
     origin LIKE "%space%"),
 query_2 AS 
    (SELECT DISTINCT origin AS usa 
     FROM `chrome-ux-report.country_us.201712` 
     WHERE origin LIKE "%space%" )
SELECT 
  ARRAY(SELECT japan FROM query_1) AS japan,
  ARRAY(SELECT usa FROM query_2) AS usa   

您还可以检查计数如下

WITH
 query_1 AS 
    (SELECT DISTINCT origin AS japan 
     FROM `chrome-ux-report.country_jp.201712` WHERE 
     origin LIKE "%space%"),
 query_2 AS 
    (SELECT DISTINCT origin AS usa 
     FROM `chrome-ux-report.country_us.201712` 
     WHERE origin LIKE "%space%" )
SELECT 
  ARRAY_LENGTH(ARRAY(SELECT japan FROM query_1)) AS japan_count,
  ARRAY_LENGTH(ARRAY(SELECT usa FROM query_2)) AS usa_count