Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

SQL Logic - UPDATE feild only when change in FLAG

S567Dec 17 2019 — edited Dec 18 2019

Hello Team,

version i am working is 11g.

Below is sample data 

select '123' cus,'1' code,'NULL' flag,'somn@gmail.com' email,'12-DEC-19' old_date from dual union 

select '456' cus,'2' code,'Y' flag,'somn@gmail.com' email,'17-DEC-19'  old_date from dual union

select '567' cus,'3' code,'NULL' flag,'somn@gmail.com' email,'16-DEC-19' old_date from dual union

  select '789' cus,'4' code,'Y' flag,'somn@gmail.com' email,'13-DEC-19' old_date from dual union

i need to define new field called latest_date to above sql , which should be updated only if any change in flag value is observed for the customer on the old_date.

  for eg cus 567 with NULL flag on 16 DEC   changed to Y on 17 DEC then latest_date should be updated as 17 DEC for all rows and  if there is no change in flag then the latest_date feild should take same value as old date.

Thanks.

This post has been answered by mNem on Dec 17 2019
Jump to Answer
Comments
Post Details
Added on Dec 17 2019
14 comments
401 views