SQL · Question 23 · Medium

SQL question 23

Table Orders:
order_id | customer | city | amount
101 | Meera | Chennai | 1200
102 | Arjun | Bengaluru | 600
103 | Meera | Chennai | NULL
104 | Sana | Delhi | 1100
105 | Arjun | Bengaluru | 600
106 | Dev | Bhopal | 300
107 | Sana | Delhi | 400

What does this query return?

SELECT AVG(amount), AVG(COALESCE(amount, 0))
FROM Orders;
  1. 700 and 600
  2. 600 and 600
  3. 700 and 700
  4. 600 and 700
Answer and explanation

Answer: A. 700 and 600

Explanation: The six non-NULL amounts total 4200. AVG ignores NULL, so AVG(amount) = 4200 / 6 = 700. COALESCE turns the NULL into 0, so the second average is 4200 / 7 = 600.

Previous: Table Orders: order_id | customer | city | amount 101 | Meera | Chennai | 1200… · Next: Table Orders: order_id | customer | city | amount 101 | Meera | Chennai | 1200…

Practise sql

Try a fresh set of sql questions with an explanation after every answer, free and without signing up: SQL practice. Or sit a full placement mock test.

More sql questions

More technical & programming practice

Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps · GenAI Basics · Pseudo-code · C Programming · Java

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge