我有这样的数据:
Valuedate cusID late
-----------------------------------
20130822 000083-AC-KH-00063 1
20130823 000083-AC-KH-00063 0
20130824 000083-AC-KH-00063 1
20130825 000083-AC-KH-00063 2
20130826 000083-AC-KH-00063 1
20131020 000170-AC-KH-00031 1
20131021 000170-AC-KH-00031 2
20131022 000170-AC-KH-00031 3
20131023 000170-AC-KH-00031 1
我需要跟踪每个客户的最迟付款,直到当前值日期,因此结果必须如下:
Valuedate cusID late max_late
--------------------------------------------
20130822 000083-AC-KH-00063 1 1
20130823 000083-AC-KH-00063 0 1
20130824 000083-AC-KH-00063 1 1
20130825 000083-AC-KH-00063 2 2
20130826 000083-AC-KH-00063 1 2
20131020 000170-AC-KH-00031 1 1
20131021 000170-AC-KH-00031 2 2
20131022 000170-AC-KH-00031 3 3
20131023 000170-AC-KH-00031 1 3
我使用以下SQL查询:
select
valuedate, cusID, late,
max(late) over (partition by cusID order by valuedate) as max_late
from
cus_late
order by
valuedate, cusID
但它总是会抛出错误:
'order'附近的语法不正确
我无法理解为什么
PS:此代码获得通用延迟日期在我的数据上运行良好:
select
valuedate, cusID, late,
max(late) over (partition by cusID ) as max_late
from
cus_late
order by
valuedate, cusID