Given a schema containing merchant sales and customer orders, construct a query that identifies merchants who experienced a month-over-month sales decline for three consecutive months.
Use completed customer orders when calculating sales. Treat consecutive months as calendar months with no gaps.
merchant_id and decline_end_monthdecline_end_month is the latest month in a qualifying three-month decline sequencemerchant_id ascending| Column | Type | Description |
|---|---|---|
| sale_idPK | INT | Unique sale identifier |
| merchant_id | INT | Merchant associated with the sale |
| order_id | INT | Customer order associated with the sale |
| sale_date | DATE | Date of the sale |
| sale_amount | DECIMAL(12,2) | Sale amount |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique customer order identifier |
| customer_id | VARCHAR(30) | Customer who placed the order |
| order_status | VARCHAR(20) | Current order status |