Practice Free
MediumAggregations

International Card Authorization Decline Concentrations

Frequently Asked By:StripeCoinbaseBloomberg
Interactive In-Browser Workspace

Practice this problem on live schema tables in PostgreSQL 16 WASM with instant row verification and visual EXPLAIN plans.

Solve in Workbench

Problem Statement

Group records in `card_authorizations` by `issuing_country` where `auth_status = 'declined'`. Calculate: 1. `issuing_country` 2. `declined_count`: Number of declined authorizations 3. `declined_volume_usd`: Sum of `amount_usd` for declined authorizations Filter groups with `HAVING COUNT(*) >= 2`. Order results by `declined_volume_usd` descending, then by `issuing_country` ascending.

Why Technical Interviewers Ask This

Payment authorization routers detect geo-specific interchange outages by tracking card decline volumes and total blocked dollar value per issuing country.

Common Pitfalls & Interview Traps

Forgetting required sorting and deterministic tie-breaking.
Not accounting for NULL or zero-value denominators during calculations.
Using inefficient quadratic subqueries instead of single-pass aggregations constructs.

Canonical Modern SQL Solution

PostgreSQL 16 / ANSI SQL
SELECT 
        issuing_country,
        COUNT(*) AS declined_count,
        SUM(amount_usd) AS declined_volume_usd
      FROM card_authorizations
      WHERE auth_status = 'declined'
      GROUP BY issuing_country
      HAVING COUNT(*) >= 2
      ORDER BY declined_volume_usd DESC, issuing_country ASC;
Approach Breakdown
This query addresses the problem requirements by filtering and structuring data in Aggregations. It meets the target criteria: Card decline count and aggregate blocked dollar amount by country.

Edge Cases to Verbally Clarify with Your Interviewer

The dataset contains zero matching records (must return valid empty result without crashing).
Multiple records tie on sorting criteria (must evaluate tie-breaking order deterministically).
Foreign keys or secondary attributes have NULL values.

Frequently Asked Follow-Up Questions

What makes this question a favorite among Stripe and Coinbase interviewers?

Interviewers use this problem to test whether candidates write defensive, scalable Aggregations queries that run efficiently on multi-million row production databases without excessive memory usage.

How does the query optimizer execute this query?

Using single-pass table scans with index lookups or sort buffers. Running EXPLAIN (ANALYZE, BUFFERS) in the DB Exercises workbench visualizes the execution nodes and buffer hit cache.

More FAANG SQL Interview Questions

View all questions