Solve a medium-difficulty data transformation problem using optimized SQL queries and window functions.
Write a PostgreSQL query that evaluates completed transactions from January 1 through March 31, 2025. Include only accounts with at least two qualifying transactions. The query should calculate each account's qualifying transaction count and total revenue, then assign its revenue rank within its segment.
account_id, account_name, segment, completed_transactions, total_revenue, and segment_rank.segment, ascending segment_rank, then ascending account_id.completed as qualifying.2025-01-01 and through 2025-03-31, excluding 2025-04-01 and later.total_revenue values the same segment_rank, leaving gaps after ties.0.| Column | Type | Description |
|---|---|---|
| account_idPK | INT | Unique account identifier |
| account_name | VARCHAR(100) | Account display name |
| segment | VARCHAR(50) | Market segment assigned to the account |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| account_id | INT | Account associated with the transaction |
| transaction_date | DATE | Date the transaction occurred |
| status | VARCHAR(20) | Transaction processing status |
| amount | DECIMAL(12,2) | Transaction revenue amount |