Monthly Transaction Volume and Average Item Price for 2099

Quick Overview

Write a SQL query that summarizes sales transactions by month for the year 2099, reporting the total sales volume and the average item price for each month. It tests filtering by a calendar year, grouping by an extracted month number, rounding, and telling a plain average apart from a quantity-weighted one.

Monthly Transaction Volume and Average Item Price for 2099

Company: Mercari

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

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. ```hint Year boundaries Apply the 2099 condition before you aggregate, and check that a transaction dated 2098-12-31 cannot end up in month 12 of your result. ``` ### 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.

Overview: Write a SQL query that summarizes sales transactions by month for the year 2099, reporting the total sales volume and the average item price for each month. It tests filtering by a calendar year, grouping by an extracted month number, rounding, and telling a plain average apart from a quantity-weighted one.

Mercari logo
Mercari
Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

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

ColumnTypeMeaning
transaction_idINTPrimary key, one row per transaction
item_idINTItem sold (not null)
quantityINTUnits sold in the transaction (not null, at least 1)
item_priceDECIMAL(10,2)Price per unit (not null, greater than 0)
transaction_dateDATEDate 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:

ColumnTypeMeaning
monthINTMonth number, 1 to 12
total_volumeDECIMALSum of quantity * item_price over the month's 2099 transactions, not rounded
avg_item_priceDECIMALAverage 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_iditem_idquantityitem_pricetransaction_date
1100250.002099-01-10
2101175.002099-01-25
3102320.002099-02-05
4103510.002099-02-18
51041200.002098-12-31

Expected output:

monthtotal_volumeavg_item_price
1175.0062.50
2110.0015.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.