Aggregates & GROUP BY · Question 16 · Hard

Aggregates & GROUP BY question 16

Table Sales:
sale_id | rep | region | amount
1 | Asif | North | 400
2 | Bina | South | 250
3 | Asif | North | NULL
4 | Chirag | South | 550
5 | Bina | West | 300
6 | Deepa | North | 600
7 | Chirag | South | 250

No sale is above 1000. How many rows does this query return?

SELECT region, COUNT(*)
FROM Sales
WHERE amount > 1000
GROUP BY region;
  1. 0 rows
  2. 1 row
  3. 3 rows
  4. 7 rows
Answer and explanation

Answer: A. 0 rows

Explanation: WHERE removes every row, so there is nothing to form groups from and a query with GROUP BY returns no rows at all. Only an aggregate query without GROUP BY returns one row (with COUNT 0) on an empty input.

Previous: Table Attendance: student | subject | month_name | days Pooja | Maths | Jan |… · Next: Table Sales: sale_id | rep | region | amount 1 | Asif | North | 400 2 | Bina |…

Practise aggregates & group by

Try a fresh set of aggregates & group by questions with an explanation after every answer, free and without signing up: Aggregates & GROUP BY practice. Or sit a full placement mock test.

More aggregates & group by questions

More sql practice

Subqueries & CTEs · Window Functions · NULL Handling · SQL Functions & CASE · UNION, INTERSECT & EXCEPT · Tables, Keys & Constraints · DML & Transactions · SELECT, WHERE & ORDER BY

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