Aggregates & GROUP BY · Question 10 · Medium

Aggregates & GROUP BY question 10

Table Attendance:
student | subject | month_name | days
Pooja | Maths | Jan | 20
Pooja | Maths | Feb | 18
Pooja | Physics | Jan | 15
Rahul | Maths | Jan | 22
Rahul | Physics | Jan | 19
Rahul | Physics | Feb | 21

How many rows does this query return?

SELECT student, subject, SUM(days)
FROM Attendance
GROUP BY student, subject;
  1. 2 rows
  2. 3 rows
  3. 4 rows
  4. 6 rows
Answer and explanation

Answer: C. 4 rows

Explanation: A group is formed for each different (student, subject) pair: Pooja-Maths, Pooja-Physics, Rahul-Maths and Rahul-Physics. The month does not matter, so 6 rows collapse to 4.

Previous: Table Tickets: ticket_id | agent | priority 1 | Sana | High 2 | NULL | Low 3 |… · 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