The Transactions table records item sales. For each month of the year 2099, report the total transaction volume (the sum of quantity * item_price) and the average item price. Only transactions whose transaction_date falls in 2099 count. Months with no 2099 transactions do not appear in the result, and if there are no 2099 transactions at all the result is empty.
Input Table(s)
Transactions
| Column | Type | Meaning |
|---|
| transaction_id | INT | Primary key, one row per transaction |
| item_id | INT | Item sold (not null) |
| quantity | INT | Units sold in the transaction (not null, at least 1) |
| item_price | DECIMAL(10,2) | Price per unit (not null, greater than 0) |
| transaction_date | DATE | Date of the transaction (not null) |
Primary key: transaction_id.
Output Contract
One row per month of 2099 that has at least one transaction, with these columns in this order:
| Column | Type | Meaning |
|---|
| month | INT | Month number, 1 to 12 |
| total_volume | DECIMAL | Sum of quantity * item_price over the month's 2099 transactions, not rounded |
| avg_item_price | DECIMAL | Average of item_price over the month's 2099 transactions, rounded to 2 decimals |
Order by month ascending. Each month appears once, so this ordering is unique.
Example
Input Transactions:
| transaction_id | item_id | quantity | item_price | transaction_date |
|---|
| 1 | 100 | 2 | 50.00 | 2099-01-10 |
| 2 | 101 | 1 | 75.00 | 2099-01-25 |
| 3 | 102 | 3 | 20.00 | 2099-02-05 |
| 4 | 103 | 5 | 10.00 | 2099-02-18 |
| 5 | 104 | 1 | 200.00 | 2098-12-31 |
Expected output:
| month | total_volume | avg_item_price |
|---|
| 1 | 175.00 | 62.50 |
| 2 | 110.00 | 15.00 |
January has volume 2 × 50 + 1 × 75 = 175 and average price (50 + 75) / 2 = 62.5. February has volume 3 × 20 + 5 × 10 = 110 and average price (20 + 10) / 2 = 15. Transaction 5 is dated 2098, so it is left out and there is no month 12 row.
Constraints and Clarifications
-
The table has 1 to 100,000 rows.
-
transaction_id
is unique, so every row is a separate transaction. The same
item_id
can appear in many transactions, and each one counts.
-
No column is NULL.
quantity
is at least 1 and
item_price
is greater than 0.
-
avg_item_price
is the plain mean of
item_price
across the month's transaction rows. It is not weighted by
quantity
.
-
Only calendar year 2099 counts. Rows dated in 2098 or 2100 are excluded even when their month number matches.
-
Months without 2099 transactions are omitted. Do not add rows with zeros for them.
-
total_volume
is not rounded. Because
item_price
has two decimal places, the sum is already exact to two decimals.