Career Soft Solutions Pvt. uses a product revenue report to identify leading products each month. Write a PostgreSQL query that ranks products by revenue within every category and month.
status is completed.quantity * unit_price, aggregated by calendar month, category, and product.product_id ascending for ties.| Column | Type | Description |
|---|---|---|
| category_idPK | INT | Primary key for a product category |
| category_name | VARCHAR(80) | Display name of the category |
| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Primary key for a product |
| product_name | VARCHAR(120) | Product display name |
| category_id | INT | Reference to categories.category_id |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Primary key for an order |
| order_date | TIMESTAMP | Timestamp when the order was placed |
| status | VARCHAR(20) | Order processing status |
| Column | Type | Description |
|---|---|---|
| order_item_idPK | INT | Primary key for an order line item |
| order_id | INT | Reference to orders.order_id |
| product_id | INT | Reference to products.product_id |
| quantity | INT | Number of units in the line item |
| unit_price | NUMERIC(12,2) | Price per unit at purchase time |