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 Statement - Please help #1

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

Error while running SQL Statement - Please help #1

soumojitdas65 opened this issue Aug 27, 2022 · 1 comment

Comments

@soumojitdas65
Copy link

soumojitdas65 commented Aug 27, 2022

[01_crypto_market_algorithm.md]

*ERROR 1370 (42000) at line 5: execute command denied to user '@'localhost' for routine 'DATEPART'.

Can you please let me know how to resolve this?
I had this question in an internal exam and couldn't solve so I checked out yours and it shows the above error.

@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