Customers With at Least One Order

SQL coding challenge · Difficulty: easy · +50 XP

Problem

You are working at an e-commerce company. The sales team wants a list of every customer who has placed at least one order.

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 |
| --- | --- | --- |
| 1 | Krishna | Hyderabad |
| 2 | Sudheer | Bangalore |
| 4 | Rahul | Hyderabad |
  • Return: customer_id, customer_name, city
  • Sort by customer_id ascending
  • Each customer should appear only once even if they have multiple orders

Solve this challenge on PySpark.in