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;
- 2 rows
- 3 rows
- 4 rows
- 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
- 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 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…
- Table Sales: sale_id | rep | region | amount 1 | Asif | North | 400 2 | Bina |…
- Table Attendance: student | subject | month_name | days Pooja | Maths | Jan |…
- Table Sales: sale_id | rep | region | amount 1 | Asif | North | 400 2 | Bina |…
- Table Sales: sale_id | rep | region | amount 1 | Asif | North | 400 2 | Bina |…
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