Customers Who Have Never Placed an Order

SQL coding challenge · Difficulty: easy · +50 XP

Problem

The marketing team is launching a re-engagement campaign. They need a list of customers who have never placed a single order to send them a special discount.

Tables

Table: Customer

| customer_id | customer_name | city |
| --- | --- | --- |
| 1 | Krishna | Hyderabad |
| 2 | Sudheer | Bangalore |
| 3 | Atul | Pune |
| 4 | Rahul | Hyderabad |

Table: Orders

| order_id | customer_id | order_date | amount | aspect |
| --- | --- | --- | --- | --- |
| 101 | 1 | 2024-05-01 | 2500.00 | Electronics |
| 102 | 1 | 2024-05-03 | 1500.00 | Books |
| 103 | 2 | 2024-05-05 | 3000.00 | Clothing |
| 104 | 4 | 2024-05-07 | 1200.00 | Books |
| 105 | 4 | 2024-05-10 | 2200.00 | Electronics |

Expected Output

| customer_id | customer_name | city |
| --- | --- | --- |
| 3 | Atul | Pune |
  • Return: customer_id, customer_name, city
  • Sort by customer_id ascending
  • Hint: Think LEFT JOIN — when there is no matching order, the order columns are NULL

Solve this challenge on PySpark.in