SQL Practice Problem #006

Find orders above the average amount

Return orders whose total amount is greater than the average order amount.

Problem

Task

Return orders whose total amount is greater than the average order amount.

Schema

Table Schema

orders(id, customer_id, total_amount, ordered_at)

Input

Sample Data

idcustomer_idtotal_amountordered_at
1011502026-03-02
10221502026-03-06
10331002026-03-09

Output

Expected Output

idcustomer_idtotal_amountordered_at
10221502026-03-06

Answer

Check Your Solution

Show Answer and Explanation

Correct Answer

SELECT *
FROM orders
WHERE total_amount > (
  SELECT AVG(total_amount)
  FROM orders
);

Explanation

The subquery calculates the average total_amount across all orders. The outer query then keeps only rows with a total_amount greater than that value.

Common Mistakes

  • Trying to use AVG(total_amount) directly in WHERE without a subquery.
  • Using >= when the problem asks for greater than the average.
  • Calculating the average per customer instead of across all orders.

Concepts

Related Concepts

Subquery AVG Scalar Subqueries Comparison

Next practice

Related Problems