我正在嘗試用最早的值填充丟失的彩色行,該值一直有效,直到使用 Postgres 資料庫中的 SQL 查詢設定新值

uj5u.com熱心網友回復:
你可以first_value()這樣使用:
select
client,
activity_date,
val,
first_value(val) over (partition by client, grp_t) as new_val
from (
select client, activity_date, val,
sum(case when val is not null then 1 end) over (order by client, activity_date) as grp_t
from filling
) t
order by 1,2,3;

這是dbfiddle示例
更新。修復了由于每個客戶端的第一行為 NULL 時的問題而導致的 new_val
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/492789.html
標籤:PostgreSQL 时间序列
