Structuring: Near-Threshold Deposits in 7 Days

SQL practice question · Hard · Subqueries & CTEs · JPMorgan, American Express

AML monitoring: a near-threshold deposit has 9000 <= amount < 10000. A 7-day window starts on the date of a near-threshold deposit d and covers d to d + 6 days inclusive. Flag an account when some window contains at least 3 near-threshold deposits. For each flagged account report its EARLIEST qualifying window: account_id, window_start, deposits_in_window (near-threshold deposits in that window) and total_in_window (their sum, ROUND 2). Order by account_id.

Table: cash_deposits

Schema of cash_deposits
ColumnType
deposit_idINTEGER
account_idTEXT
deposit_dateDATE
amountREAL
Sample rows of cash_deposits
deposit_idaccount_iddeposit_dateamount
1AC12026-02-019500
2AC12026-02-039800
3AC12026-02-069100
4AC12026-02-209900
5AC22026-02-019500
6AC22026-02-0512000
7AC22026-02-079400
8AC32026-02-109999
Expected output on the sample data
account_idwindow_startdeposits_in_windowtotal_in_window
AC12026-02-01328400
AC32026-02-10328199

Solve it in the live editor on this page — run on sample data, then submit against hidden tests.

‹ Rolling 7-Day Notional With Missing Days · 90th Percentile Spend per Card Tier ›

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Question Asked in Interview Blog
SQL Interview Practice

Company-wise SQL questions

{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.

🏆 Weekly SQL Contest
{{ totalCount }}
Questions
{{ companyCount }}
Companies
{{ prog.total.solved }}
Solved
Bookmark Question Companies Difficulty Category Status
{{ r.n }} - {{ r.title }} {{ c }} {{ r.difficulty }} {{ r.category }} {{ r.statusIcon }}
No questions match these filters.
Showing {{ rangeLabel }} of {{ filteredCount }}

Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.

← All questions

{{ cur.n }} - {{ cur.title }}

🏆 Contest {{ contestWeek }}
{{ cur.catLabel }} {{ cur.diffLabel }} {{ c }}
Embed this questionPaste on a blog, course page or LMS. Free to use — educator guide
{{ embedCode }}

{{ cur.statement }}

Table: {{ tb.name }}
ColumnType {{ c.name }}{{ c.type }}
{{ h }} {{ v.text }}
Expected output on the sample data:
{{ h }} {{ v.text }}
  • {{ h }}

No submissions yet. Press Evaluate to submit your query.

{{ s.verdict }} {{ s.meta }}
The solution unlocks after you solve this question or after 3 evaluations that didn't pass ({{ failCount }}/3 so far). Trying first is the fastest way to learn.
{{ solutionSql }}
  1. {{ e }}
⏱ {{ timerLabel }}
{{ fnHelpTitle }}
{{ fnHelpText }}
Writing {{ dialectName }} · Ctrl/Cmd + Enter runs the query · Tab indents · your code is saved automatically
Output {{ out.status }}
  • {{ w }}
{{ out.verdict }}
{{ out.detail }}
{{ out.error }}
Expected (sample data)
{{ h }}{{ v.text }}
Your output (sample data)
{{ h }}{{ v.text }}
{{ h }} {{ v.text }}
Run your query to see the result here.
🔒

To Track Your Progress, Log In / Sign Up

You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.

Sign Up Free Log In