with table1 (ID_BOOK,MONTH_BOOK,QUALITY_BOOK,DPD) as (
VALUES
(1110, '201911', 4, 22)
,(1110, '201910', 3, 15)
,(1110, '201907', 1, 2)
,(1117, '201911', 2, 2)
,(1117, '201909', 3, 7)
,(1117, '201907', 2, 7)
,(2114, '201911', 3, 7)
,(2114, '201910', 3, 7)
,(2114, '201909', 1, 0)
,(2114, '201908', 1, 0)
,(3226, '201911', 5, 19)
,(3226, '201910', 4, 10)
,(3226, '201908', 1, 4)
,(4555, '201911', 2, 11)
,(4555, '201910', 2, 10)
,(7888, '201911', 2, 12)
,(7888, '201910', 2, 12)
)
select
this.id_book as current_id_book,
this.month_book as current_month_book ,
this.quality_book as current_quality_book,
this.dpd as current_dpd,
old.id_book as old_id_book,
old.month_book as old_month_book ,
old.quality_book as old_quality_book,
old.dpd as old_dpd
from
TABLE1 as this
inner join TABLE1 as old on
old.ID_BOOK = this.ID_BOOK
and old.MONTH_BOOK =
to_char(to_date(this.MONTH_BOOK,'YYYYMM') - 1 month, 'YYYYMM')
where
this.MONTH_BOOK = '201911'
and (this.QUALITY_BOOK > old.QUALITY_BOOK
or this.DPD > old.DPD)