SQL QuestSQL Interview Questions › Joins

Inactive Customers by Tier

MediumFreeQuerying BasicsJoinsConditional LogicAggregation & GroupingSubqueries & CTEs

Which membership tier has the highest share of inactive customers (zero orders)? For each membership, show total_customers, inactive_customers (customers whose order_count is 0), and inactive_pct (rounded to 1 decimal, as a percentage of total_customers in that tier). Sort by inactive_pct descending. This is a classic LEFT JOIN + conditional aggregation pipeline: first get order counts per customer, then roll up by tier.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

customers

customer_idnameemailsignup_datemembershiptotal_orders
1John Smithjohn.smith@email.com2023-01-15Gold15
2Emma Wilsonemma.wilson@email.com2023-03-20Silver8
3Michael Brownmichael.brown@email.com2023-02-10Gold12

orders

order_idcustomer_idproductcategoryquantitypricetotalorder_datecountrystatus
11Laptop ProElectronics11299.991299.992024-01-15USAcompleted
22Wireless MouseElectronics249.9999.982024-01-16Canadacompleted
33Office ChairFurniture1349.99349.992024-01-17USAcompleted

Expected output: Silver | 10 | 3 | 30.0

Hint

First compute per-customer order_count with LEFT JOIN (customers without orders get order_count = 0). Then roll up by membership, counting how many had order_count = 0 using SUM(CASE WHEN order_count = 0 THEN 1 ELSE 0 END).

Concepts

SELECT LEFT JOIN CASE GROUP BY Derived Table LEFT JOIN + CASE

Practise the topic: SQL practice questions · JOIN practice · CASE WHEN practice · GROUP BY exercises · CTE practice

In these company practice sets

Amazon · Ramp · Snowflake · Stripe · TikTok

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Customers Who Never OrderedMedium · FreeAbove-Average Departments (Derived Table)Medium · FreeLEFT JOIN NULL Semantics: Inactive CustomersMedium · FreeManagement Hierarchy OverviewMedium · FreeCount Direct ReportsMedium · FreeCustomer Recency AnalysisMedium · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test