"错误:字段' [已删除] .field_id'在JOIN",Google BigQuery

时间:2017-06-01 17:20:30

标签: google-bigquery

作为Google的BigQuery平台的初学者,我发现它与MySql的语法几乎相似。但是,我收到了一个问题,我的查询中没有找到我正在执行的内部联接两侧的列。

以下示例查询:

SELECT
  base_account.random_table_name_transaction.context_id,
  base_account.random_table_name_transaction.transaction_id,
  base_account.random_table_name_transaction.meta_recordDate,
  base_account.random_table_name_transaction.transaction_total,
  base_account.random_table_name_transaction.view_id,
  base_account.random_table_name_view.user_id,
  base_account.random_table_name_view.view_id,
  base_account.random_table_name_view.new_vs_returning,
  base_account.random_table_name_experience.view_id,
  base_account.random_table_name_experience.experienceId,
  base_account.random_table_name_experience.experienceName,
  base_account.random_table_name_experience.variationName,
  base_account.random_table_name_experience.iterationId,
  base_account.random_table_name_experience.isControl
FROM
  [base_account.random_table_name_transaction] transactiontable
INNER JOIN
  base_account.random_table_name_view viewtable
ON
  transactiontable.view_id=viewtable.view_id
INNER JOIN
  [base_account.random_table_name_experience] experiencetable
ON
  viewtable.view_id=experiencetable.view_id
WHERE experiencetable.experienceId = 96659 or experiencetable.experienceId = 96660

在这种情况下,当我在BigQuery平台中运行它时,在运行查询几秒后,我返回一个错误: "Error: Field 'base_account.random_table_name_experience.experienceId' not found on either side of the JOIN"

但是,当我运行相同的查询时,我会执行SELECT *查询,它会正确执行并返回我期望的数据。

我的语法是否缺少其失败的原因?我可以确认我试图返回的每一列确实存在于每个受尊重的表中。

1 个答案:

答案 0 :(得分:3)

确保使用standard SQL进行查询,以避免遗留SQL的一些令人惊讶的别名规则,并获取更多信息性错误消息。您的查询将是:

#standardSQL
SELECT
  base_account.random_table_name_transaction.context_id,
  base_account.random_table_name_transaction.transaction_id,
  base_account.random_table_name_transaction.meta_recordDate,
  base_account.random_table_name_transaction.transaction_total,
  base_account.random_table_name_transaction.view_id,
  base_account.random_table_name_view.user_id,
  base_account.random_table_name_view.view_id,
  base_account.random_table_name_view.new_vs_returning,
  base_account.random_table_name_experience.view_id,
  base_account.random_table_name_experience.experienceId,
  base_account.random_table_name_experience.experienceName,
  base_account.random_table_name_experience.variationName,
  base_account.random_table_name_experience.iterationId,
  base_account.random_table_name_experience.isControl
FROM
  `base_account.random_table_name_transaction` transactiontable
INNER JOIN
  base_account.random_table_name_view viewtable
ON
  transactiontable.view_id=viewtable.view_id
INNER JOIN
  `base_account.random_table_name_experience` experiencetable
ON
  viewtable.view_id=experiencetable.view_id
WHERE experiencetable.experienceId = 96659 OR experiencetable.experienceId = 96660;

请注意,我所做的唯一更改是将#standardSQL放在开头(启用标准SQL)并使用反引号而不是括号来转义表名。