Aggregates & GROUP BY · Question 8 · Medium

Aggregates & GROUP BY question 8

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

Which reps does this query return?

SELECT rep
FROM Sales
GROUP BY rep
HAVING COUNT(amount) > 1
ORDER BY rep;
  1. Asif; Bina; Chirag
  2. Deepa
  3. Asif; Bina; Chirag; Deepa
  4. Bina; Chirag
Answer and explanation

Answer: D. Bina; Chirag

Explanation: COUNT(amount) counts only non-NULL amounts. Asif has two rows but one amount is NULL, so his count is 1 and he fails the HAVING test. Bina and Chirag each have 2.

Previous: Table Innings: inn_id | batter | team | runs 1 | Kunal | Tigers | 45 2 | Kunal… · Next: Table Tickets: ticket_id | agent | priority 1 | Sana | High 2 | NULL | Low 3 |…

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