背景:需要列出用戶一天中24小時每個小時的累計消費,通過用戶消費記錄的結束時間與時間表關聯后,只能累計計算出有過消費的小時如圖:0點到1點累計消費10元,1點到2點無消費,2點到3點累計消費20。
現在對空字段進行補空值,使用lag只能對上一行進行補,無法補多個連續空值。
解決:開窗求出當前行到第一行中最大值進行部位
max(money_total) over(partition by user_id order by create_time rows between unbounded preceding and current row)
nvl(max(money_total) over(partition by user_id order by create_time rows between unbounded preceding and current row) , 0)