通过 Cloud Datalab 加入 Google BigQuery

Join in Google BigQuery via Cloud Datalab

我正在尝试对 Google BigQuery 中两个不同表(其中一个是视图)的两个列进行 JOIN。我已经尝试了很多方法,但最经常收到此错误:

invalidQuery: 2.1 - 0.0: JOIN cannot be applied directly to a table union or to a table wildcard function. Consider wrapping the table union or table wildcard function in a subquery (e.g., SELECT *).

这是我的 SQL(旧版)查询:

SELECT 
  blp_today.beta_key,
  blp_today.px_last,
  blp_today.eqy_weighted_avg_px,
  blp_today.created_date,
  blp_today.security_ticker,
  ciq_company_stg.ticker,
  ciq_company_stg.ciq
FROM 
  [fcm-dw:acquisition_bloomberg.blp_today],
  [fcm-dw:acquisition_ciq] 
JOIN
  blp_today.security_ticker AS ticker
ON
  blp_today.security_ticker = ciq_company_stg.ticker
LIMIT 1000

如有任何帮助,我们将不胜感激。

我想你要么想要这样的东西:

SELECT * FROM(SELECT 
  beta_key,
  px_last,
  eqy_weighted_avg_px,
  created_date,
  security_ticker,
FROM 
  [fcm-dw:acquisition_bloomberg.blp_today],
  [fcm-dw:acquisition_ciq] ) as  a
JOIN
  blp_today.security_ticker AS ticker
ON
  a.security_ticker = ciq_company_stg.ticker
LIMIT 1000

//edit:我之前有点想念您正在加入的 table(在您的加入语句之后)实际上似乎不是 table。您是否尝试加入或合并这两个 tables:[fcm-dw:acquisition_bloomberg.blp_today] 和 [fcm-dw:acquisition_ciq]?后者甚至是table吗?您的代码似乎表明还有另一个 table 名为:[fcm-dw:acquisition_ciq.ciq_company_stg]?

首先将你的联合包装成一个子select然后加入结果

select ...
FROM 
(select * from 
  [fcm-dw:acquisition_bloomberg.blp_today],
  [fcm-dw:acquisition_ciq] ) t
JOIN
  blp_today.security_ticker AS ticker