Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while running SQL Query - Please help #2

Open
soumojitdas65 opened this issue Aug 27, 2022 · 1 comment
Open

Error while running SQL Query - Please help #2

soumojitdas65 opened this issue Aug 27, 2022 · 1 comment

Comments

@soumojitdas65
Copy link

[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.

@navya2320
Copy link

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants