Your question is Consecutive-Month Customer Orders. Start with the requirements and the four tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Eaton's business analysts need to identify customers showing sustained purchasing activity across consecutive calendar months. The analysis should use completed orders for Eaton electrical products and ignore duplicate orders within the same month.
Write a PostgreSQL query that identifies customers who placed qualifying orders in at least one pair of consecutive calendar months.
order_status = 'Completed', non-null order dates, and products in the Electrical business unit.customer_id ascending.customers includes customers without qualifying orders, while orders includes canceled, undated, and non-qualifying examples. Multiple rows can belong to the same customer or order.
| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer business name |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| customer_id | INT | Customer who placed the order |
| order_date | DATE | Date the order was placed |
| order_status | VARCHAR(20) | Order status |
| Column | Type | Description |
|---|---|---|
| order_id | INT | Order containing the item |
| product_id | INT | Product included in the order |
| quantity | INT | Quantity ordered |
| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique product identifier |
| product_name | VARCHAR(100) | Eaton product name |
| business_unit | VARCHAR(50) | Eaton product business unit |