Aggregates & GROUP BY · Question 4 · Easy
Aggregates & GROUP BY question 4
Table Innings:
inn_id | batter | team | runs
1 | Kunal | Tigers | 45
2 | Kunal | Tigers | 0
3 | Lalit | Tigers | 72
4 | Mohan | Lions | 30
5 | Mohan | Lions | NULL
6 | Naveen | Lions | 58
7 | Naveen | Lions | 62
What does this query return?
SELECT batter, SUM(runs)
FROM Innings
GROUP BY batter
ORDER BY batter;
- Kunal, 45; Lalit, 72; Mohan, NULL; Naveen, 120
- Kunal, 45; Lalit, 72; Naveen, 120
- Kunal, 2; Lalit, 1; Mohan, 2; Naveen, 2
- Kunal, 45; Lalit, 72; Mohan, 30; Naveen, 120
Answer and explanation
Answer: D. Kunal, 45; Lalit, 72; Mohan, 30; Naveen, 120
Explanation: SUM adds the non-NULL values in each group. Mohan's NULL innings is skipped, so his total is 30, not NULL; Naveen has 58 + 62 = 120.
Previous: A table Sales(sale_id, rep, region, amount) has no NULL in region. Which… · 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 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 |…
- A table Sales(sale_id, rep, region, amount) has no NULL in region. Which…
- Table Sales: sale_id | rep | region | amount 1 | Asif | North | 400 2 | Bina |…
- A table Sales(sale_id, rep, region, amount) is given. Which query returns the…
- 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 |…
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