Average Quantity
Given the transactions table, write a query to get the average quantity of each product purchased for each transaction, every year.
The output should include the year, product_id, and average quantity for that product sorted by year and product_id ascending. Round avg_quantity to two decimal places.
Example:
Input:
transactions
table
Columns | Type |
---|---|
id |
INTEGER |
user_id |
INTEGER |
created_at |
DATETIME |
product_id |
INTEGER |
quantity |
INTEGER |
Output:
Columns | Type |
---|---|
year |
INTEGER |
product_id |
INTEGER |
avg_quantity |
DECIMAL |
.....
Loading editor