Above Average Product Prices

Start Timer

0:00:00

Upvote
1
Downvote
Save question
Mark as completed
View comments (41)

Given a table of transactions and products, write a query to retrieve three columns product_id, product_price, and avg_transaction_total where:

  1. avg_transaction_total is the average of (price * quantity) over all transactions for each product.

  2. We only want products whose product_price is strictly greater than their own avg_transaction_total.

Notes: - Round the values to two decimal places.

Example:

Input:

transactions table

Column Type
id INTEGER
user_id INTEGER
created_at DATETIME
product_id INTEGER
quantity INTEGER

products table

Column Type
id INTEGER
name VARCHAR
price FLOAT
.
.
.
.
.


Comments

Loading comments