Sellers With No Sales - Problem
Find Sellers With No Sales
You're analyzing a webstore's sales data to identify underperforming sellers. Given three database tables -
Tables:
•
•
•
Goal: Write a SQL query to return the names of all sellers who had zero sales in 2020, ordered alphabetically by seller name.
This is a classic SQL problem that tests your understanding of JOINs, date filtering, and finding missing relationships between tables.
You're analyzing a webstore's sales data to identify underperforming sellers. Given three database tables -
Customer, Orders, and Seller - your task is to find all sellers who didn't make any sales during the year 2020.Tables:
•
Customer: Contains customer information•
Orders: Contains all order transactions with sale dates•
Seller: Contains seller informationGoal: Write a SQL query to return the names of all sellers who had zero sales in 2020, ordered alphabetically by seller name.
This is a classic SQL problem that tests your understanding of JOINs, date filtering, and finding missing relationships between tables.
Input & Output
example_1.sql — Basic Case
$
Input:
Customer:
| customer_id | customer_name |
|-------------|---------------|
| 1 | Alice |
| 2 | Bob |
Orders:
| order_id | sale_date | customer_id | seller_id |
|----------|------------|-------------|-----------|
| 1 | 2020-03-01 | 1 | 1 |
| 2 | 2020-05-25 | 2 | 3 |
| 3 | 2021-02-15 | 1 | 2 |
Seller:
| seller_id | seller_name |
|-----------|-------------|
| 1 | Alice |
| 2 | Bob |
| 3 | Carol |
›
Output:
| seller_name |
|-------------|
| Bob |
💡 Note:
Bob (seller_id=2) only has a sale in 2021, not in 2020. Alice and Carol both have sales in 2020, so only Bob is returned.
example_2.sql — Multiple No-Sales Sellers
$
Input:
Customer:
| customer_id | customer_name |
|-------------|---------------|
| 1 | John |
Orders:
| order_id | sale_date | customer_id | seller_id |
|----------|------------|-------------|-----------|
| 1 | 2020-01-01 | 1 | 1 |
Seller:
| seller_id | seller_name |
|-----------|-------------|
| 1 | Alice |
| 2 | Bob |
| 3 | Carol |
| 4 | Dave |
›
Output:
| seller_name |
|-------------|
| Bob |
| Carol |
| Dave |
💡 Note:
Only Alice (seller_id=1) made a sale in 2020. Bob, Carol, and Dave made no sales, so they are returned in alphabetical order.
example_3.sql — All Sellers Have Sales
$
Input:
Customer:
| customer_id | customer_name |
|-------------|---------------|
| 1 | John |
| 2 | Jane |
Orders:
| order_id | sale_date | customer_id | seller_id |
|----------|------------|-------------|-----------|
| 1 | 2020-01-01 | 1 | 1 |
| 2 | 2020-06-15 | 2 | 2 |
Seller:
| seller_id | seller_name |
|-----------|-------------|
| 1 | Alice |
| 2 | Bob |
›
Output:
| seller_name |
|-------------|
💡 Note:
Both Alice and Bob made sales in 2020, so no sellers are returned (empty result set).
Visualization
Tap to expand
Understanding the Visualization
1
Identify the Tables
We need Seller (all salespeople) and Orders (2020 transactions only)
2
LEFT JOIN Strategy
Connect every seller with their 2020 orders, preserving sellers with no orders
3
Filter for Missing
Find sellers where the join produced NULL (no 2020 sales)
4
Sort Results
Order alphabetically by seller name
Key Takeaway
🎯 Key Insight: LEFT JOIN preserves all records from the left table (Seller), making it perfect for finding missing relationships. The WHERE IS NULL filter identifies sellers without any 2020 sales.
Time & Space Complexity
Time Complexity
O(n×m)
n sellers × m orders to check each seller against all orders
✓ Linear Growth
Space Complexity
O(1)
No additional space needed beyond result set
✓ Linear Space
Constraints
- 1 ≤ Number of customers ≤ 104
- 1 ≤ Number of orders ≤ 105
- 1 ≤ Number of sellers ≤ 103
- sale_date is in YYYY-MM-DD format
- All seller_id values in Orders table exist in Seller table
- Results must be ordered by seller_name in ascending order
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code