【问题标题】:Window function is not supported in partition by clausespartition by 子句不支持窗口函数
【发布时间】:2021-08-05 14:24:11
【问题描述】:
select t1.lease_number ,t2.rec_bal, to_date(t2.date_dim_id,'YYYYMMDD') as issue_date,t2.paid_to as pay_date,
(case when pay_date <= lag(pay_date) over (order by issue_date) then null when pay_date > lag(pay_date) over (order by issue_date) then issue_date end) as payment_date,
dense_rank() over (partition by pay_date order by issue_date) as row_numbers,
(case when row_numbers = max(row_numbers) over (partition by payment_date) then payment_date else null end) as paymentmade_date,
remain_months_upd,remaining_pymt_periods, t2.dealer_dim_id, t2.lease_contract_dim_id

from dm_business_ops_tcci.v_tcci_lease_contract_dim t1
, dm_business_ops_tcci.v_tcci_lease_transaction_fact t2

where t1.lease_contract_dim_id=t2.lease_contract_dim_id
and t2.date_dim_id >=20210301 -- can be changed to latest busienss date
and lease_number in (1633014)
order by issue_date

我正在尝试按使用窗口函数创建的列进行分区,但我做不到。错误来自“(row_numbers = max(row_numbers) over (partition by payment_date) then payment_date else null end) as paymentmade_date”这一行。 Payment_date 正在使用前一行中的窗口函数进行计算。有解决办法吗?

【问题讨论】:

    标签: sql amazon-redshift window-functions


    【解决方案1】:

    在对该值执行任何类型的过滤、分区或条件操作之前,您需要具体化窗口函数的值。

    有几种方法可以做到这一点,适合您的用例的方法将根据此范围之外的因素而有所不同。

    您可以在尝试此分区操作之前使用视图、CTE、临时表或表变量来完成此操作。这不是一份详尽的清单。

    【讨论】:

    • 感谢您的来信。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 2019-02-18
    • 2015-11-29
    • 2014-10-23
    • 2011-09-07
    • 2011-07-25
    • 2016-09-14
    相关资源
    最近更新 更多