SQL QuestSQL Interview Questions › Joins

Membership Tier Revenue Analysis

MediumFreeQuerying BasicsJoinsAggregation & GroupingNULL Handling

For each membership tier (Gold, Silver, etc.), show: membership, customer_count (total customers in tier), active_customers (those with at least one order), total_revenue (2 dec), and avg_revenue_per_customer (total / all customers, 2 dec). Include members with zero orders. Sort by total_revenue descending.

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: Membership tiers with revenue and activity metrics

Hint

LEFT JOIN to keep all customers. COUNT(DISTINCT c.customer_id) for total, COUNT(DISTINCT o.customer_id) for active. Divide total_revenue by total customer count for avg

Concepts

SELECT LEFT JOIN GROUP BY Aggregation COALESCE DISTINCT JOIN + GROUP BY

Practise the topic: SQL practice questions · JOIN practice · GROUP BY exercises · NULL handling practice

In these company practice sets

Meta · Shopify · Snowflake · Stripe · Walmart · Microsoft

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