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?
- SELECT region, COUNT(*) FROM Sales GROUP BY region;
- SELECT region, COUNT(*) FROM Sales ORDER BY region;
- SELECT COUNT(DISTINCT region) FROM Sales;
- 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
- A table Sales(sale_id, rep, region, amount) has no NULL in region. Which…
- Table Innings: inn_id | batter | team | runs 1 | Kunal | Tigers | 45 2 | Kunal…
- Table Sales: sale_id | rep | region | amount 1 | Asif | North | 400 2 | Bina |…
- Table Innings: inn_id | batter | team | runs 1 | Kunal | Tigers | 45 2 | Kunal…
- Table Sales: sale_id | rep | region | amount 1 | Asif | North | 400 2 | Bina |…
- Table Tickets: ticket_id | agent | priority 1 | Sana | High 2 | NULL | Low 3 |…
- Table Attendance: student | subject | month_name | days Pooja | Maths | Jan |…
- Table Sales: sale_id | rep | region | amount 1 | Asif | North | 400 2 | Bina |…
- Table Innings: inn_id | batter | team | runs 1 | Kunal | Tigers | 45 2 | Kunal…
- A table Sales(sale_id, rep, region, amount) is given. Which query lists the…
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