AML & Fraud Analytics Path · Mission 8 of 30Easy

Dormant accounts that just woke up

Aggregate + subquery / HAVING to surface accounts with long-dormant gaps and a sudden large credit

Back to AML & Fraud Analytics

The Brief

Maya EllsworthFraud Ops Leadfraud-ops

Run the dormant-then-active query. For every account, figure out the gap between its most recent transaction and the one before. I want accounts where the most recent transaction is a cash deposit of at least $10,000, AND that transaction is at least 365 days after the prior transaction on that account. That's the "money mule waking up" pattern — an account that went quiet for a year and then suddenly takes in a big cash amount. Return account_id, the prior_last_date, and the wake_date. Exclude reversals throughout.

You'll practice

MAXDate arithmeticHAVING

Tables & columns available

aml_transactionsfact9 columns
ColumnTypeKey
txn_idINTPK
account_idINTFK → aml_accounts
posted_dateTEXT
posted_tsTEXT
amountREAL
channelTEXT
counterparty_nameTEXT
counterparty_account_idINT
is_reversalINT

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

This is a per-account ordering problem. The cleanest approach: use `LAG(posted_date) OVER (PARTITION BY account_id ORDER BY posted_date)` to get the prior transaction's date on each row.

Hint 2

Then in the outer query, filter: the current row must be a `cash_deposit` of `amount >= 10000` with `is_reversal = 0`, AND `(posted_date - prior_date) >= 365` days. Cast the date strings or use julianday() depending on your dialect.

Hint 3

SQLite date math: julianday(posted_date) - julianday(prior_date) >= 365 works against TEXT dates in YYYY-MM-DD format.