sql - 更新红移表上的 is_latest 列
问题描述
我正在尝试更新由以下更新语句分组的 redshift 表上的列is_latest
,但收到一个错误,即在更新语句中不允许使用窗口函数。解决此问题的最佳方法是什么?source
source_primary_key
update my_schema.production_log
set is_latest =
case when run_start_time = max(run_start_time) over (partition by
source, source_primary_key)
then ‘t’ else ‘f’
end
解决方案
Redshift 支持FROM
语句中的子句update
。尝试这个:
update my_schema.production_log
set is_latest = (case when run_start_time = max_run_start_time
then 't' else 'f'
end)
from (select source, source_primary_key, max(run_start_time) as max_run_start_time
from my_schema.production_log
group by source, source_primary_key
) pl2
where pl2.source = production_log.source and
pl2.source_primary_key = production_log.source_primary_key;
推荐阅读
- css - SVG 缩放 (100% - 60px)
- c# - 在每个非字母/非数字字符处拆分字符串
- reactjs - Webpack:414 Request-URI Too Long for an image
- php - 如何修复来自 php 页面的评论在页面重新加载时重复发布?
- node.js - 节点 10 无法安装 package.json 中列出的依赖项
- delphi - 如何在 Delphi 中将 TMemo 用于电子邮件正文
- azure-data-factory - 在 Azure 数据工厂中将行数转换为 INT
- .net - .NET Core 3.1 - SQL Server - 创建新的登录名和用户 - 参数问题
- java - Hibernate 可以将子选择中的 1:M 连接的结果集映射到具有子集合的父级吗?
- arrays - 在 MongoDB 中查询数组