To get the old value and the new value

create table test (ID NUMBER,
Number of REV,
Number FIELD_ID,
FieldName varchar2 (200),
ACTION varchar2 (50).
Field_value varchar2 (200),
MODIFIED_BY varchar2 (50).
Date MODIFIED_DATE);

Insert into TEST (ID, REV, FIELD_ID, FIELD_NAME, ACTION, FIELD_VALUE, MODIFIED_BY, MODIFIED_DATE) values (1007,283,12,'status','UPDATE','Started','2002',to_date('13-DEC-13','DD-MON-RR'));
Insert into TEST (ID, REV, FIELD_ID, FIELD_NAME, ACTION, FIELD_VALUE, MODIFIED_BY, MODIFIED_DATE) values (1007,224,12,'status','UPDATE','preview','2002',to_date('12-DEC-13','DD-MON-RR'));
Insert into TEST (ID, REV, FIELD_ID, FIELD_NAME, ACTION, FIELD_VALUE, MODIFIED_BY, MODIFIED_DATE) values (1007,290,12,'status','UPDATE','revision','2002',to_date('14-DEC-13','DD-MON-RR'));


Insert into TEST (ID, REV, FIELD_ID, FIELD_NAME, ACTION, FIELD_VALUE, MODIFIED_BY, MODIFIED_DATE) values (1008,283,12,'status','UPDATE','Started','2002',to_date('13-DEC-13','DD-MON-RR'));
Insert into TEST (ID, REV, FIELD_ID, FIELD_NAME, ACTION, FIELD_VALUE, MODIFIED_BY, MODIFIED_DATE) values (1008,224,12,'status','UPDATE','preview','2002',to_date('12-DEC-13','DD-MON-RR'));
Insert into TEST (ID, REV, FIELD_ID, FIELD_NAME, ACTION, FIELD_VALUE, MODIFIED_BY, MODIFIED_DATE) values (1008,290,12,'status','UPDATE','teststat','2002',to_date('14-DEC-13','DD-MON-RR'));

1007 283 12 status of started the UPDATE 2002 13 December 13
1007 224 12 status update overview 2002 12 December 13
12 290 1007 State review UPDATED 2002 December 14, 13
1008 283 12 status of started the UPDATE 2002 13 December 13
1008 224 12 status update overview 2002 12 December 13
1008 290 12 intensified status 2002 Update December 14, 13

I need to Get for each id for each field Ineed to get the old value and new_value.


Planned result for the simulacrum of the data is:

ID FIELD_NAME ACTION OLD_FIELD_VALUE NEW_FIELD_VALUE MODIFIED_BY MODIFIED_DATE
1007 status UPDATE started review 2002 December 14, 13
1008 State updated started intensified 2002 December 14, 13


Thank you
Ann

Hello

9728f65c-CE79-4c28-9efb-9e76dc6eaf8b wrote:

Yes I need a production line for all id.the the last rows should be the one with the highest rev.

Then use id where I guessed a group of columns starting with id and rev in most of the places where I used modifed_date:

WITH got_analytics AS

(

SELECT id, field_name, action

LAG (field_value) over (PARTITION BY ID.

ORDER BY rev

) AS old_field_value

field_value AS new_field_value

modified_by

modified_date

rev

MAX (rev) over (PARTITION BY id)

AS max_rev

OF the test

)

SELECT id, field_name, old_field_value, new_field_value, modified_by, modified_date

OF got_analytics

WHERE rev = max_rev

ORDER BY id

;

Tags: Database

Similar Questions

Maybe you are looking for

  • How to retrieve deleted files from a server?

    I didn't know where to put this, especially so if someone could direct me to the correct forum, as well, that would be fantastic. Brief summary of the situation: I work for a small business that keeps all our files very important (relevant to the man

  • HP Pavilion 15-p042ax: R7 M260 Windows 7 driver problem

    Hello I have a laptop HP Pavilion 15-p042ax model #: K2N74PA with AMD R5 and R7 integrated map Video, recently lowered the victory note 8.1 for windows 7, I can't get the drivers AMD R7 M260 to work (yellow! mark). Installed very well R5 I tried sp68

  • New windows open as narrow screens instead of the full screen

    original title: WHEN YOU OPEN a NEW WINDOW IT OPENS ON a NARROW instead of FULL SCREEN mode WINDOW. WHY? AND HOW TO CHANGE THIWS SETTING? for some reason any (Ithink my fiance ' has done something) when I open a new window opens in a narrow band at t

  • BlackBerry Getting My Blackberry next week Z10 Z10

    Get my Blackberry Z10 next week As everyone had any tips using the Blackbeery Z10 with MAC OS X. THKS

  • Why can't I register for ePrint?

    I fill in every box, but it won't work... I have to fill my email and password once, but when I press "make account", it is this line above my e-mail and password: (translated from Dutch) 'emails must match. 'Passwords must match' What is this kind o