Etsy wants to identify its most active buyers using recent purchase activity. Write a SQL query to find the top 10% of active buyers based on purchase frequency during the previous 90 days, including their spending and most frequently purchased product category.
buyer_id, purchase_frequency, total_spend, and primary_category.primary_category as the category with the most purchases by that buyer. Break category ties alphabetically, placing a NULL category last.| Column | Type | Description |
|---|---|---|
| buyer_idPK | INT | Unique Etsy buyer identifier |
| buyer_name | VARCHAR(100) | Buyer display name |
| VARCHAR(255) | Buyer email address |
| Column | Type | Description |
|---|---|---|
| purchase_idPK | INT | Unique purchase identifier |
| buyer_id | INT | Buyer who made the purchase |
| product_id | INT | Purchased listing identifier |
| purchased_at | TIMESTAMP | Timestamp when the purchase was made |
| amount | DECIMAL(10,2) | Purchase amount in dollars |
| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique listing identifier |
| product_name | VARCHAR(150) | Etsy listing name |
| category | VARCHAR(80) | Product category |