Aggregates & GROUP BY · Question 19 · Hard

Aggregates & GROUP BY question 19

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

What does this query return?

SELECT MAX(total)
FROM (SELECT rep, SUM(amount) AS total
      FROM Sales
      GROUP BY rep) t;
  1. 600
  2. 800
  3. 2350
  4. 550
Answer and explanation

Answer: B. 800

Explanation: The inner query gives totals per rep: Asif 400, Bina 550, Chirag 800, Deepa 600. The outer MAX picks the largest of these, 800. 600 is only the largest single sale and 2350 is the grand total.

Previous: Table Innings: inn_id | batter | team | runs 1 | Kunal | Tigers | 45 2 | Kunal… · Next: Table Sales(sale_id, rep, region, amount) has the regions North, South and…

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