Practice Free
EasyFundamentals

Dormant SaaS Tenants with Missing Payment Methods

Frequently Asked By:AmazonGoogleMeta
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

Find all records in the `organizations` table where: - `billing_tier` is one of `'Starter'`, `'Professional'`, or `'Enterprise'` - `stripe_customer_id` is `NULL` Return: 1. `org_id` 2. `org_name` 3. `billing_tier` 4. `created_at` Order the results by `created_at` ascending, then by `org_id` ascending.

Why Technical Interviewers Ask This

CloudScale's billing service fails when organizations upgrade beyond the free trial but have no saved payment method. The finance team needs an urgent audit list of all paying tenants whose `stripe_customer_id` is NULL.

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 fundamentals constructs.

Canonical Modern SQL Solution

PostgreSQL 16 / ANSI SQL
SELECT 
        org_id,
        org_name,
        billing_tier,
        created_at
      FROM organizations
      WHERE billing_tier IN ('Starter', 'Professional', 'Enterprise')
        AND stripe_customer_id IS NULL
      ORDER BY created_at ASC, org_id ASC;
Approach Breakdown
This query addresses the problem requirements by filtering and structuring data in Fundamentals. It meets the target criteria: Paid tier accounts missing payment provider credentials, sorted by creation date.

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 Amazon and Google interviewers?

Interviewers use this problem to test whether candidates write defensive, scalable Fundamentals 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