SQL QuestSQL Interview Questions › Joins

Membership × Country Activity (Cross Join)

MediumFreeQuerying BasicsJoinsAggregation & Grouping

Marketing wants a membership-tier × country activity grid: every (membership, country) cell with the count of orders placed by customers of that tier from that country — including empty cells.

CROSS JOIN distinct memberships (from customers) with distinct countries (from orders), then LEFT JOIN orders + customers to count. Show membership, country, order_count (0 when none). Order by membership, then country.

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: 28 rows, many with order_count = 0

Hint

The hint for this one spells out most of the query, so it stays in the editor. Reach for SELECT, CROSS JOIN, LEFT JOIN, and open the hint there if you stall.

Concepts

SELECT CROSS JOIN LEFT JOIN GROUP BY Cross Join

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

In these company practice sets

Wise

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