How would you optimize a slow-running SQL query involving millions of rows?
Use the supplied PostgreSQL tables to return successful transactions during January 2025. The solution should be suitable for a large transaction table and preserve customers whose qualifying transactions have a NULL amount.
customer_id, customer_name, successful_recharge_count, and total_amount.total_amount descending, then customer_id ascending.| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer display name |
| segment | VARCHAR(30) | Optional customer segment |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | BIGINT | Unique recharge transaction identifier |
| customer_id | INT | Customer associated with the transaction |
| amount | NUMERIC(12,2) | Recharge amount |
| transaction_ts | TIMESTAMP | Transaction timestamp |
| status | VARCHAR(20) | Transaction processing status |
| channel | VARCHAR(20) | Recharge channel |