RienSQL
TASK #223 · Hard · Santander

Rolling 7-Day Charges

Your brief
Santander's anti-fraud team monitors how much money leaves an account over 7 days. The rolling sum of an account on date D is the total of its charges (tx_type = 'cargo') with tx_date from D − 6 days to D inclusive, i.e. over 7 calendar days.

Write a query that calculates the rolling sum for each account and each date on which that account had a charge, and returns the rows where it is strictly greater than 1000 €: account_id, tx_date and rolling_7d. Each (account, date) pair must appear once.
Expected columnsaccount_id tx_date rolling_7dSantander
SQL editor
SQLite
Ctrl / ⌘ + ↵
Result

Write a query and run it to see the results.

Schema
customerscustomer_id, full_name, city
accountsaccount_id, customer_id, account_type, balance, overdraft_limit
transactionstransaction_id, account_id, tx_date, tx_type, amount, description