The Apexon Data & AI platform tracks high-volume user transactions across regions. Write a PostgreSQL query that identifies the three most purchased items in each region during the last 30 days, using completed transactions only.
region, item_id, item_name, purchased_units, and region_rank.item_id, and order the final result by region and region_rank.| Column | Type | Description |
|---|---|---|
| transaction_idPK | BIGINT | Unique transaction identifier |
| user_id | BIGINT | References users.user_id |
| item_id | BIGINT | References items.item_id |
| quantity | INTEGER | Number of units in the transaction |
| occurred_at | TIMESTAMP | Timestamp when the transaction occurred |
| status | VARCHAR(20) | Transaction processing status |
| Column | Type | Description |
|---|---|---|
| user_idPK | BIGINT | Unique user identifier |
| region | VARCHAR(40) | Geographic region assigned to the user |
| Column | Type | Description |
|---|---|---|
| item_idPK | BIGINT | Unique item identifier |
| item_name | VARCHAR(100) | Display name of the purchased item |