0
← Exercises/
Aggregations•10 of 12
AggregationsIntermediatePRO

ATM Cash Depletion & Peak Withdrawal Volume

Scenario

Bank vault logistics must route cash replenishment trucks before ATMs run dry over holiday weekends. The operations desk needs a list of ATM terminals where total cash dispensed today exceeds $20,000 across at least 3 transactions.

Task
Group transactions in `atm_withdrawals` by `terminal_id` and `branch_location`. Calculate: 1. `terminal_id` 2. `branch_location` 3. `withdrawal_count`: Total count of withdrawal events 4. `total_cash_dispensed`: Sum of `dispensed_usd` 5. `avg_withdrawal_size`: `ROUND(AVG(dispensed_usd), 2)` Use `HAVING` to only include terminals where `total_cash_dispensed >= 20000.00` AND `withdrawal_count >= 3`. Order results by `total_cash_dispensed` descending.
Expected Output Format

High-volume ATMs requiring priority cash restocking, sorted by cash dispensed.

Input Tables & Sample Data0 tables
Loading database schema...
Need a hint?
query.sql|Local Sandbox
Loading SQL editor...
Click "Run" or press ⌘ + Enter to execute your query

About the “ATM Cash Depletion & Peak Withdrawal Volume” SQL Problem

Business Scenario

Bank vault logistics must route cash replenishment trucks before ATMs run dry over holiday weekends. The operations desk needs a list of ATM terminals where total cash dispensed today exceeds $20,000 across at least 3 transactions.

Expected Output & Criteria

High-volume ATMs requiring priority cash restocking, sorted by cash dispensed.

Database Table Schema (PostgreSQL DDL)

PostgreSQL 16 WASM

This challenge executes directly against the following relational schema in your browser:

CREATE TABLE atm_withdrawals (
        withdrawal_id INT PRIMARY KEY,
        terminal_id VARCHAR(20) NOT NULL,
        branch_location VARCHAR(80) NOT NULL,
        dispensed_usd NUMERIC(10, 2) NOT NULL
      );

Target SQL Clauses & Operators

GROUP BYSUMCOUNTHAVING

Want more Aggregations practice?

Explore the full syllabus of 12 exercises, syntax guides, and interview pitfalls.

View Aggregations Track→