You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
try to identify suspicious transactions based on the defined criteria.
WITH ranked_transactions AS (
SELECT
sender,
dt,
amount,
UNIX_TIMESTAMP(dt) AS ts,
LAG(UNIX_TIMESTAMP(dt)) OVER (PARTITION BY sender ORDER BY dt) AS prev_ts,
LAG(amount) OVER (PARTITION BY sender ORDER BY dt) AS prev_amount
FROM
transactions
),
sequences AS (
SELECT
sender,
dt,
amount,
ts,
CASE
WHEN ts - prev_ts <= 3600 OR prev_ts IS NULL THEN 0
ELSE 1
END AS is_start
FROM
ranked_transactions
),
cumulative_amounts AS (
SELECT
sender,
dt,
amount,
ts,
SUM(is_start) OVER (PARTITION BY sender ORDER BY dt) AS seq_id
FROM
sequences
),
suspicious_sequences AS (
SELECT
sender,
MIN(dt) AS sequence_start,
MAX(dt) AS sequence_end,
COUNT() AS transactions_count,
ROUND(SUM(amount), 6) AS transactions_sum
FROM
cumulative_amounts
GROUP BY
sender,
seq_id
HAVING
COUNT() >= 2
AND SUM(amount) >= 150
)
SELECT
sender,
sequence_start,
sequence_end,
transactions_count,
transactions_sum
FROM
suspicious_sequences
ORDER BY
sender,
sequence_start;
[02_crypto_transactions_monitoring.md]
ERROR 1582 (42000) at line 5: Incorrect parameter count in the call to native function 'DATEDIFF'
Can you help me with why this error is showing? I couldn't solve it.
The text was updated successfully, but these errors were encountered: