SQL - Redshift 滞后函数重复

SQL - Redshift Lag Function getting duplicates

下面有一个table

ID  Type  Sub_ID   Date    CNT
A    P     A1    4/1/2020   5
A    P     A2    4/5/2020   NULL
A    P     A3    4/8/2020   NULL

我想得到的是

ID  Type  Sub_ID   Date    CNT    LAG
A    P     A1    4/1/2020   5     NULL
A    P     A2    4/5/2020   NULL   5
A    P     A3    4/8/2020   NULL   NULL

我有以下查询,但它给了我重复项,例如

ID  Type  Sub_ID   Date    CNT    LAG
A    P     A1    4/1/2020   5     NULL
A    P     A1    4/1/2020   5      5 (duplicate)
A    P     A2    4/5/2020   NULL   5 
A    P     A2    4/5/2020   NULL   NULL (duplicate)
A    P     A3    4/8/2020   NULL   NULL

select *, lag(cnt,1) over (partition by id, type order by date)
from mytable

有什么问题吗?

好的...我的 table 中有重复数据..需要先进行重复数据删除,然后在清理后的基础上进行延迟 table