Bigquery SQL:使用键值 table 转换 table 值

Bigquery SQL: Convert table values using a key-value table

我有两个 table。 第一个 table 包含键值数据:

   Answer_Code |Fruit
   1           |Apple
   2           |Orange
   3           |Pear
   4           |Watermelon

第二个table包含收集的数据

   Participant|Fruit
   Aaa        |1
   Bbb        |2
   Ccc        |3

如何连接这些 table,以便第二个 table 中的 Fruit 列将替换为第一个 table 中的 Fruit 值?

   Participant|Fruit
   Aaa        |Apple
   Bbb        |Orange
   Ccc        |Watermelon

我试过以下方法:

SELECT T1.*, T2.*,
FROM [Table1] T1, 
JOIN [Table2] T2 ON T1.Fruit = T2.Fruit,
LIMIT 10;

我收到以下错误:

ON 子句必须是 AND of = 每个 table 中的一个字段名称的比较,所有字段名称都以 table 名称为前缀。考虑使用标准 SQL .google.com/bigquery/docs/reference/standard-sql/),它允许涉及表达式和剩余谓词的非相等 JOIN 和比较。

此外,我无法获得更新,无法在 bigquery 上工作。

您的 ON 子句不正确
而不是 ON T1.Fruit = T2.Fruit 你应该 ON T1.Answer_Code = T2.Fruit
另外,您的查询中几乎没有多余的逗号

无论如何,您的查询应该如下所示

SELECT T2.Participant, T1.Fruit
FROM [Table1] T1 
RIGHT JOIN [Table2] T2 ON T1.Answer_Code = T2.Fruit
LIMIT 10   

也推荐给migrate to BigQuery Standard SQL - Standard SQL is the preferred SQL dialect for querying data stored in BigQuery and also has multiple advantages including DML这样可以get UPDATE, SET to work on BigQuery