I need to program a query where I can see the changes that certain fields have undergone in a certain date period. Example: From the CAM_CONCEN table bring those records where the ACCOUNT_NUMBER undergoes a modification in the CONCTACT field in a period of 6 months before the date. I would be grateful if you can guide me.
Advertisement
Answer
You can use LAG()
to peek at the previous row of a particular subset of rows (the same account in this case).
For example:
select * from ( select c.*, lag(contact) over(partition by account_number order by change_date) as prev_contact from cam_concen c ) x where contact <> prev_contact