Orders Above Average Amount

SQL coding challenge · Difficulty: easy · Topic: Subquery vs CTE Patterns · +50 XP

A company wants to identify orders that are larger than the average order amount across all orders. Given an 'orders' table, return the order_id, customer_id, order_date, and amount for each order whose amount is strictly greater than the average amount of all orders. An order whose amount is exactly equal to the average is not included. The result should be sorted by order_id ascending.

Example Input

`

orders table:

order_id | customer_id | order_date | amount

1 | 201 | 2024-01-01 | 100.00

2 | 202 | 2024-01-02 | 200.00

3 | 203 | 2024-01-03 | 150.00

4 | 204 | 2024-01-04 | 300.00

5 | 205 | 2024-01-05 | 250.00

6 | 206 | 2024-01-06 | 120.00

7 | 207 | 2024-01-07 | 180.00

`

Expected Output

`

order_id | customer_id | order_date | amount

2 | 202 | 2024-01-02 | 200.00

4 | 204 | 2024-01-04 | 300.00

5 | 205 | 2024-01-05 | 250.00

`

What this SQL challenge teaches you

“Orders Above Average Amount” is a easy-level SQL challenge focused on Subquery vs CTE Patterns. Working through it gives you hands-on practice with CTE, subquery, aggregation, filtering — the kind of transformation you are asked to write in real data engineering work and in technical interviews. You can solve it directly in the browser: the dataset is pre-loaded, so you write the query or DataFrame code, run it, and compare your output against the expected result immediately.

Concepts covered

How to approach it

If you get stuck, work through these steps in order before looking at a full solution — each one narrows the problem down:

  1. 1 ≤ number of rows ≤ 10,000
  2. Each order_id is unique
  3. customer_id is a positive integer
  4. order_date is a valid DATE in YYYY-MM-DD format
  5. amount is a positive decimal with two fractional digits
  6. Return columns: order_id (INTEGER), customer_id (INTEGER), order_date (DATE), amount (DECIMAL(10,2)), sorted by order_id ASC
  7. Orders with amount equal to the average are excluded

How to practise it on PySpark.in

Open the challenge, write your SQL query in the editor and press Run to execute it against the sample dataset. Submitting checks your output against every test case, including hidden ones, so you find out straight away whether your logic holds up. You can retry as often as you like, and each solved challenge adds to your XP.

Related SQL challenges

Helpful resources

Frequently asked questions

Do I need to install Spark or a database to solve this?

No. The SQL environment runs in your browser with the sample data already loaded, so there is nothing to install or configure.

Is this challenge free?

Yes - the problem, the sample dataset, the hints and unlimited test runs are free.

What level is it?

It is rated easy and covers Subquery vs CTE Patterns.

Solve this challenge free on PySpark.in