Merchant Category Transaction Summary
Problem statement
Summarize credit-card transactions by merchant category.
Return each category's average transaction amount rounded to two decimal places and its total transaction amount. Order categories by total amount descending, then category ascending.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
transactions
| Column | Type | Nullable | Description |
|---|---|---|---|
| transaction_idPK | Integer | No | — |
| merchant_category | Text | No | — |
| transaction_amount | Decimal | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| merchant_category | Text | No | — |
| average_transaction_amount | Decimal | No | — |
| total_transaction_amount | Decimal | No | — |
Row order: must match exactly. Numeric tolerance: 0.001.
Constraints
- Every transaction has one merchant category and amount.
- Category labels in a case are distinct under ordinary database text comparison.
- Round only the displayed average; keep exact totals.