Sellers With No Sales - Problem

Given three tables - Customer, Orders, and Seller - find all sellers who did not make any sales in the year 2020.

The Customer table contains customer information, the Orders table contains all sales transactions with dates, and the Seller table contains seller information.

Return the result ordered by seller_name in ascending order.

Table Schema

Customer
Column Name Type Description
customer_id PK int Primary key for customer
customer_name varchar Name of the customer
Primary Key: customer_id
Orders
Column Name Type Description
order_id PK int Primary key for order
sale_date date Date when transaction was made
order_cost int Cost of the order
customer_id int Foreign key to Customer table
seller_id int Foreign key to Seller table
Primary Key: order_id
Seller
Column Name Type Description
seller_id PK int Primary key for seller
seller_name varchar Name of the seller
Primary Key: seller_id

Input & Output

Example 1 — Mixed Sales Activity
Input Tables:
Customer
customer_id customer_name
1 Daniel
2 Elizabeth
Orders
order_id sale_date order_cost customer_id seller_id
1 2020-03-01 1500 1 1
2 2020-05-25 2400 2 3
Seller
seller_id seller_name
1 Alice
2 Bob
3 Charlie
Output:
seller_name
Bob
💡 Note:

Alice (seller_id=1) made a sale on 2020-03-01, and Charlie (seller_id=3) made a sale on 2020-05-25. Only Bob (seller_id=2) has no sales in 2020, so he appears in the result.

Example 2 — All Sellers Have Sales
Input Tables:
Customer
customer_id customer_name
1 John
Orders
order_id sale_date order_cost customer_id seller_id
1 2020-01-15 1000 1 1
2 2020-12-31 2000 1 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 appear in the result (empty result set).

Example 3 — Sales Outside 2020
Input Tables:
Customer
customer_id customer_name
1 Sarah
Orders
order_id sale_date order_cost customer_id seller_id
1 2019-12-31 500 1 1
2 2021-01-01 800 1 2
Seller
seller_id seller_name
1 David
2 Emma
Output:
seller_name
David
Emma
💡 Note:

Both sellers have sales, but none occurred in 2020 (one in 2019, one in 2021). Since we only look for 2020 sales, both sellers are included in the result, ordered alphabetically.

Constraints

  • 1 ≤ seller_id, customer_id ≤ 100
  • 1 ≤ order_id ≤ 1000
  • seller_name and customer_name are non-empty strings
  • sale_date is a valid date
  • order_cost ≥ 0

Visualization

Tap to expand
Finding Sellers With No 2020 SalesInput: Three TablesSellerAlice (1)Bob (2)Charlie (3)2020 OrdersAlice: ✓Bob: ✗Charlie: ✓Filter sellerswith no 2020 salesOutputseller_nameBobTwo main approaches: LEFT JOIN with NULL checkor NOT EXISTS subquery
Understanding the Visualization
1
Input Tables
Customer, Orders, and Seller tables
2
Join/Filter
Find sellers without 2020 sales
3
Output
Sellers with no 2020 activity
Key Takeaway
🎯 Key Insight: Use LEFT JOIN or NOT EXISTS to find missing relationships between tables
Asked in
Amazon 15 Microsoft 12 Apple 8
23.5K Views
Medium Frequency
~12 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen