Last active
October 22, 2019 14:12
-
-
Save JohnAmican/82d794c28c7037af9fcc8bcb5c0cf51a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH q AS ( | |
SELECT id, | |
root_id, | |
version, | |
lag(version) OVER (PARTITION BY root_id ORDER BY root_id, version) as prev_version, | |
lead(version) OVER (PARTITION BY root_id ORDER BY root_id, version) as next_version, | |
latest | |
FROM trades | |
ORDER BY root_id, version | |
) | |
SELECT id, root_id, version, latest | |
FROM q | |
WHERE (next_version IS NOT NULL AND next_version - version <> 1) | |
OR (prev_version IS NULL AND version <> 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment