Skip to content

Instantly share code, notes, and snippets.

@ldenson11
Created January 29, 2020 22:09
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 ldenson11/ed800331e0eca6e85af7fc471d4cd211 to your computer and use it in GitHub Desktop.
Save ldenson11/ed800331e0eca6e85af7fc471d4cd211 to your computer and use it in GitHub Desktop.
SELECT *
FROM paymentauths
MATCH_RECOGNIZE(
PARTITION BY card
ORDER BY eventTimestamp
MEASURES
F.amount AS first_amount,
E.amount AS last_amount
ONE ROW PER MATCH
AFTER MATCH SKIP PAST LAST ROW
PATTERN (F+ E) -- match 1 or more rows
DEFINE
F AS F.amount IS NOT NULL AND F.amount > 10, -- lower boundary
E AS E.amount IS NOT NULL AND F.amount < E.amount) -- starting value less than ending value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment