根据 Teradata 中的修改日期创建虚拟加载日期 table

create dummy load date table based on modified date in Teradata

这更像是记录比较。如何在此处添加结束日期?请注意,最后一个日期来自表 B。示例:

表A

PROD     | PRICE | EffDATE
----------------------------- 
Product1 |    | 03/17/2015  
Product1 |    | 03/20/2015  
Product1 |    | 03/22/2015

表B

PROD     | PROMOSTART | PROMOEND
----------------------------------
Product1 | 03/17/2015 | 03/24/2015 

预期输出:

 PROD     | PRICE | StartDATE  | EndDATE 
-----------------------------------------
Product1 |    | 03/17/2015  | 03/19/2015
Product1 |    | 03/20/2015  | 03/21/2015
Product1 |    | 03/22/2015  | **03/24/2015**

如何在 Teradata SQL 中实现?

试试这个:

SELECT a.*,
   COALESCE(MIN(EffDATE) -- next row's date
            OVER (PARTITION BY a.PROD
                  ORDER BY EffDATE
                  ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING) -1
           ,b.PROMOEND)  -- or end of promo
FROM tableA AS a
JOIN tableB AS b
  ON a.PROD = b.PROD
 AND a.EffDATE BETWEEN b.PROMOSTART AND b.PROMOEND