SQL · Question 30 · Hard

SQL question 30

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 COUNT(*), SUM(amount)
FROM Orders
WHERE amount > 5000;
  1. 0 and 0
  2. NULL and NULL
  3. 0 and NULL
  4. No row at all
Answer and explanation

Answer: C. 0 and NULL

Explanation: No order exceeds 5000, so the aggregates run over an empty set. Without GROUP BY, an aggregate query still returns one row: COUNT(*) gives 0, while SUM of no values gives NULL.

Previous: 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