Link to home
Start Free TrialLog in
Avatar of angel7170
angel7170Flag for United States of America

asked on

Oracle SQL query help

Hello,

I need help with writing query in Oracle SQL to get data from the next and previous row based on the conditions. I tried using LAG and LEAD functions but not getting the results as expected. I am attaching an excel file showing how the current setup of the data with the rules that needs to be applied. I have also included the expected result. Please help
Sample-Request.xls
Avatar of Sean Stuber
Sean Stuber

>>Take the FIRST record's CREATED_TS and consider it as REQUEST_BEGIN_TS.

Does that mean we should ignore the value in the REQUEST_BEGIN_TS  column?
In your example you have it populated with the value in CREATED_TS, but your comment implies we should use CREATED_TS instead and not actually use the already supplied REQUEST_BEGIN_TS.

Is that correct?
Avatar of angel7170

ASKER

Sorry, I forgot to remove "REQUEST_BEGIN_TS" and "REQUEST_END_TS" column from the current setup. Those two columns I tried to create it by using LAG and LEAD functions but doesn't seem to work. So please ignore those columns

Yes, I need to populate the REQUEST_BEGIN_TS with the value in CREATED_TS. Thank you
ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome! Honestly, I spent 2 weeks on this one query but still with no luck. Thank you so much for the query as it is working as expected.

You guys are genius! Thank you