【发布时间】:2016-09-30 14:42:42
【问题描述】:
需要帮助,请,
我有一个名为“hist_lastupdated”的字段,其中包含产品价格修改的最后更新日期。
基于此字段,我想提取修改的开始日期和结束日期。
其实我有这个:
**Product_id , Price , hist_lastupdated**
284849 18.95 2015-05-29 00:53:55
284849 15.95 2015-08-14 01:04:46
284849 18.95 2016-06-11 00:50:31
284849 15.95 2016-08-24 00:45:11
我想得到这样的结果:
**Product_id , Price , hist_lastupdated ,start_date , End_date**
284849 18.95 2015-05-29 00:53:55 2014-05-01 00:00:00 2015-05-29 00:53:55
284849 15.95 2015-08-14 01:04:46 2015-05-29 00:53:55 2015-08-14 01:04:46
284849 18.95 2016-06-11 00:50:31 2015-08-14 01:04:46 2016-06-11 00:50:31
284849 15.95 2016-08-24 00:45:11 2016-06-11 00:50:31 2016-08-24 00:45:11
两个字,开始日期是上一行的结束日期 我有很多产品ID
【问题讨论】:
-
你想要 Postgres 中的 lag() 函数——不知道 Redshift 是否支持这个。您是否同时使用两个 DBMS?
-
@horse_with_no_name 看起来 LAG 也在 Redshift 中:docs.aws.amazon.com/redshift/latest/dg/r_WF_LAG.html
-
有朋友告诉我可以用'With Function'发布
标签: sql postgresql amazon-redshift