Given a table Orders containing compressed order data, calculate the average number of items per order rounded to 2 decimal places.
The table contains:
order_id: Unique identifier for each order typeitem_count: Number of items in this order typeorder_occurrences: How many times this order type occurred
Since the data is compressed, you need to expand it mathematically to find the true average across all individual orders.
Table Schema
| Column Name | Type | Description |
|---|---|---|
order_id
PK
|
int | Unique identifier for each order type |
item_count
|
int | Number of items in this order type |
order_occurrences
|
int | How many times this order type occurred |
Input & Output
| order_id | item_count | order_occurrences |
|---|---|---|
| 1 | 10 | 5 |
| 2 | 6 | 4 |
| 3 | 8 | 3 |
| average_items_per_order |
|---|
| 8.17 |
We have 3 order types: 5 orders with 10 items each (50 total), 4 orders with 6 items each (24 total), and 3 orders with 8 items each (24 total). Total items = 50 + 24 + 24 = 98. Total orders = 5 + 4 + 3 = 12. Average = 98/12 = 8.1666... ≈ 8.17
| order_id | item_count | order_occurrences |
|---|---|---|
| 1 | 15 | 3 |
| average_items_per_order |
|---|
| 15 |
With only one order type, all 3 orders have exactly 15 items each. Total items = 15 × 3 = 45. Total orders = 3. Average = 45/3 = 15.00
| order_id | item_count | order_occurrences |
|---|---|---|
| 1 | 1 | 10 |
| 2 | 20 | 2 |
| average_items_per_order |
|---|
| 4.17 |
We have 10 small orders (1 item each) and 2 large orders (20 items each). Total items = 1×10 + 20×2 = 50. Total orders = 10 + 2 = 12. Average = 50/12 = 4.1666... ≈ 4.17
Constraints
-
1 ≤ order_id ≤ 1000 -
1 ≤ item_count ≤ 1000 -
1 ≤ order_occurrences ≤ 1000 - All values are positive integers
- Result should be rounded to exactly 2 decimal places