sql - 如何更新由标准 SQL 中的查询创建的表?
问题描述
我在标准 SQL 中创建了一个表。在此表中,我有一个名为 COUNTRY 的列。在结果中,我看到我有巴西和巴西,还有英国和大不列颠,所以我想更新其中一个以匹配另一个,因为我想做的分析是一样的。有任何想法吗?
解决方案
以下是 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, '|'));
推荐阅读
- php - Laravel 库存分配
- javascript - 使用 javascript 的动态行编号
- rest - Django Rest Framework - 尝试将具有 1 个属性的 json 模型添加为数组时出现序列化程序错误
- java - 保存新实体时如何防止出现此 DataIntegrityViolationException?
- java - 一个 Android Studio 项目卸载另一个
- azure - 将 Azure SQL 移动到另一个订阅
- groovy - 在 Nextflow 流程中尝试 catch
- c# - System.Net.Http.HttpRequestException: '无法建立 SSL 连接
- python - 将 Tkinter 用于字幕应用程序,Python
- angular - 订阅行为主体,再次修改数据&设置值导致死循环