Interview Query

Average Quantity

17
Have you seen this question before?

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
Next question: Rectangle Overlap
.....
MySQL 8.0.17
Loading editor
Use Shift + Enter to run query