Aggregates & GROUP BY · Question 12 · Medium
Aggregates & GROUP BY question 12
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 (averages shown without trailing decimal zeros)?
SELECT team, AVG(runs)
FROM Innings
GROUP BY team
ORDER BY team;
- Lions, 37.5; Tigers, 39
- Lions, 50; Tigers, 58.5
- Lions, 37.5; Tigers, 58.5
- Lions, 50; Tigers, 39
Answer and explanation
Answer: D. Lions, 50; Tigers, 39
Explanation: AVG divides the sum by the number of non-NULL values. Lions: (30 + 58 + 62) ÷ 3 = 50, since the NULL innings is skipped. Tigers: (45 + 0 + 72) ÷ 3 = 39, since 0 is a real value and is counted.
Previous: Table Sales: sale_id | rep | region | amount 1 | Asif | North | 400 2 | Bina |… · Next: A table Sales(sale_id, rep, region, amount) is given. Which query lists the…
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 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 |…
- 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 |…
- 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 |…
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