Aggregation examples
Examples of aggregation queries that use tumbling windows.
The examples use the TUMBLE window table-valued function. For more information,
see Windowing.
Hourly payment volume
SELECT
window_end AS ts,
SUM(CAST(amount AS NUMERIC)) AS payment_volume
FROM TABLE(
TUMBLE(TABLE payments, DESCRIPTOR(eventTimestamp), INTERVAL '1' HOUR))
GROUP BY window_start, window_end;
Several authorizations for one card
Detect several authorizations for the same card in a short window, which might indicate fraud:
SELECT
card,
MAX(amount) AS theamount,
window_end AS ts
FROM TABLE(
TUMBLE(TABLE payments, DESCRIPTOR(eventTimestamp), INTERVAL '5' MINUTE))
WHERE lat IS NOT NULL
AND lon IS NOT NULL
GROUP BY card, window_start, window_end
HAVING COUNT(*) > 4;
