Experts Exchange connects you with the people and services you need so you can get back to work.
In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!
CASE WHEN start_date - 1 <= prevend THEN prevstart ELSE start_date END start_date,
CASE WHEN end_date + 1 >= nextstart THEN nextend ELSE end_date END end_date,
FROM (SELECT start_date,
LAG(start_date) OVER (PARTITION BY VALUE ORDER BY start_date) prevstart,
LAG(end_date) OVER (PARTITION BY VALUE ORDER BY start_date) prevend,
LEAD(start_date) OVER (PARTITION BY VALUE ORDER BY start_date) nextstart,
LEAD(end_date) OVER (PARTITION BY VALUE ORDER BY start_date) nextend
FROM your_table) x
ORDER BY start_date, end_date, VALUE
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.