首页 > 解决方案 > 如何更新由标准 SQL 中的查询创建的表?

问题描述

我在标准 SQL 中创建了一个表。在此表中,我有一个名为 COUNTRY 的列。在结果中,我看到我有巴西和巴西,还有英国和大不列颠,所以我想更新其中一个以匹配另一个,因为我想做的分析是一样的。有任何想法吗?

标签: sqlgoogle-bigquery

解决方案


以下是 BigQuery 标准 SQL

update your_table t
set country = d.country 
from (
  select 'Brazil' country, 'Brasil' matches union all
  select 'United Kingdom', 'UK|Great Britain|GB' union all
  select 'USA', 'US'
) d 
where t.country in unnest(split(matches, '|'));

推荐阅读