Aggregates & GROUP BY · Question 6 · Easy

A table Sales(sale_id, rep, region, amount) is given. Which query returns the number of sales made in each region?

  1. SELECT region, COUNT(*) FROM Sales GROUP BY region;
  2. SELECT region, COUNT(*) FROM Sales ORDER BY region;
  3. SELECT COUNT(DISTINCT region) FROM Sales;
  4. SELECT region, SUM(region) FROM Sales GROUP BY region;
Answer and explanation

Answer: A. SELECT region, COUNT(*) FROM Sales GROUP BY region;

Explanation: One row per region needs GROUP BY region, and COUNT(*) counts the rows in each group. ORDER BY only sorts, and COUNT(DISTINCT region) returns a single number, the number of regions.

Previous: Table Sales: sale_id | rep | region | amount 1 | Asif | North | 400 2 | Bina |… · Next: Table Innings: inn_id | batter | team | runs 1 | Kunal | Tigers | 45 2 | Kunal…

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