【发布时间】:2022-01-25 06:23:03
【问题描述】:
我想获取最后三张发票的付款到期日期并将其与付款日期进行比较,并且只需要选择那些满足该条件的客户,我尝试实现如下示例,但它没有提供所需的输出。
我想检查所有最后三张发票的到期日期,并将其与所有最后三张发票的付款日期进行比较,因此按子查询中的最后修改对行进行排序,并尝试使用 rownum >= 3 对每个客户仅最后三个进行排序
但问题是我只得到三行,即 rownum >= 3 被应用于整个查询,而不仅仅是内部查询
select c.cust_node_id
from payment pay
inner join (select i.payment_due_date as pay_due_date,
cnh.customer_node_id as cust_node_id,
i.invoice_id as inv_id
from invoice i
inner join customer_node_history cnh
on i.customer_node_id = cnh.customer_node_id and
i.current_due = 0 and
rownum >= 3 and
cnh.customer_node_type_id = customer_node_type_id
order by last_modified) c
on pay.invoice_id = c.invoice_id and
c.pay_due_date <= pay.payment_date;
【问题讨论】:
标签: sql oracle nested-queries