您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

保留值,直到Teradata中的值发生变化为止

保留值,直到Teradata中的值发生变化为止

有几种方法可以得到此结果,Teradata中最简单的方法是使用时间序列的时间段扩展:

WITH cte AS
 (
   SELECT Cust_id, Balance, Txn_dt,
      -- return the next row's date
      Coalesce(Min(Txn_dt)
               Over (PARTITION BY Cust_id 
                     ORDER BY Txn_dt
                     ROWS BETWEEN 1 Following AND 1 Following)
              ,Txn_dt+1) AS next_Txn_dt
   FROM tab
 ) 
SELECT Cust_id, Balance
  ,Last(pd) -- last day of the period
FROM cte
-- make a period of the current and next row's date
-- and return one row per day
EXPAND ON PERIOD(Txn_dt, next_Txn_dt) AS pd

如果您运行TD16.10 +,则可以将替换MIN OVER为简化的LEAD

Lead(Txn_dt)
Over (PARTITION BY Cust_id 
      ORDER BY Txn_dt)
其他 2022/1/1 18:51:03 有403人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶