+-------------------+------+
|Column Name |Type|+-------------------+------+
| order_id | int || item_count | int || order_occurrences | int |+-------------------+------+ order_id is column of unique values for this table.
This tablecontains order_id, item_count, and order_occurrences.
Write a solution to calculate the average number of items per order, rounded to 2decimal places.
Input: Orders table:+----------+------------+-------------------+| order_id | item_count | order_occurrences |+----------+------------+-------------------+|10|1|500||11|2|1000||12|3|800||13|4|1000|+----------+------------+-------------------+**Output**+-------------------------+| average_items_per_order |+-------------------------+|2.70|+-------------------------+**Explanation** The calculation is as follows:- Total items:(1*500)+(2*1000)+(3*800)+(4*1000)=8900- Total orders:500+1000+800+1000=3300- Therefore, the average items per order is8900/3300=2.70
To find the average number of items per order, we need the total number of items (item_count × order_occurrences for each row) divided by the total number of orders (sum of order_occurrences). This is a weighted mean, and SQL’s SUM and ROUND functions make it straightforward.