Skip to content

Instantly share code, notes, and snippets.

@StanAngeloff
Created October 23, 2014 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StanAngeloff/b26c7cbc31d75f10d198 to your computer and use it in GitHub Desktop.
Save StanAngeloff/b26c7cbc31d75f10d198 to your computer and use it in GitHub Desktop.
SELECT "log"."audit"->>'entity' "entity", "log"."audit"->>'requestId' "requestId", "log".*
FROM "audit_log" "log"
WHERE ("log"."audit"->>'requestId') IS NOT NULL AND NOT EXISTS (
SELECT 1
FROM "audit_log" "log2"
WHERE ("log2"."audit"->>'requestId')::numeric = (("log"."audit"->>'requestId')::numeric - 1)
AND ("log2"."audit"->>'entity') = ("log"."audit"->>'entity')
)
ORDER BY "log"."audit"->>'entity' ASC, "log"."date_logged" ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment