我有一张表,包括CONTRACT_ID,ADDENDUM_ID和PAYMENT_MONTH(年度合约的付款日期)。 每次因系统中的任何原因发生更新时:
答案 0 :(得分:0)
如果我正确理解了您想要的输出,可能会有所帮助:
with test(contract_id, addendum_id, payment_month) as
(
select 155, 1, 1 from dual union all
select 155, 1, 2 from dual union all
select 155, 1, 3 from dual union all
select 155, 1, 4 from dual union all
select 155, 1, 5 from dual union all
select 155, 1, 6 from dual union all
select 155, 1, 7 from dual union all
select 155, 1, 8 from dual union all
select 155, 1, 9 from dual union all
select 155, 1, 10 from dual union all
select 155, 1, 11 from dual union all
select 155, 1, 12 from dual union all
select 155, 2, 5 from dual union all
select 155, 2, 6 from dual union all
select 155, 2, 7 from dual union all
select 155, 2, 8 from dual union all
select 155, 2, 9 from dual union all
select 155, 2, 10 from dual union all
select 155, 2, 11 from dual union all
select 155, 2, 12 from dual union all
select 155, 3, 10 from dual union all
select 155, 3, 11 from dual union all
select 155, 3, 12 from dual
)
select contract_id, addendum_id, payment_month from (
select
max(addendum_id) over ( partition by payment_month) as max_addendum_id,
contract_id, payment_month, addendum_id
from test
)
where max_addendum_id = addendum_id
order by 1, 2, 3