Problem
An online retail company wants to analyze customer spending trends over months. Write a SQL query to calculate the total spending for each customer by month, along with the cumulative spending for each customer over time.
Requirements
- Join the
customersandorderstables oncustomer_id. - Group the results by customer and month of the order date.
- Calculate total spending per customer per month.
- Use a window function to calculate cumulative spending for each customer.
Schema
customers
| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique identifier for each customer |
| customer_name | VARCHAR(255) | Name of the customer |
orders
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique identifier for each order |
| customer_id | INT | Identifier linking to the customer who made the order |
| order_date | DATE | Date when the order was placed |
| amount | DECIMAL(10,2) | Total amount of the order |
You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.



