SQL · Question 21 · Medium

SQL question 21

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

How many rows does this query return?

SELECT customer, SUM(amount)
FROM Orders
GROUP BY customer
HAVING SUM(amount) > 1000;
  1. 2
  2. 3
  3. 4
  4. 1
Answer and explanation

Answer: B. 3

Explanation: SUM ignores NULL, so the totals are Meera 1200, Arjun 1200, Sana 1500 and Dev 300. Three groups exceed 1000 (Meera, Arjun and Sana).

Previous: Which type of join returns all rows from both tables, matching rows where… · 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