Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • 1
    Best thing you can do to help us help you is update your post with example before and after data. The Table definitions wouldn't hurt too. After reading your post, it sounds like you're trying to solve the kind of problem that a window function like ROW_NUMBER() or LAG() / LEAD() would be good for, and the issues you've ran into with them are likely trivial to solve. Commented Jul 20, 2022 at 12:15
  • 1
    For performance question, we need to see at a minimum relevant table, view and index definitions, and please share the query plan via pastetheplan.com. The question is not really answerable without that. Commented Jul 20, 2022 at 12:59