Three questions on GROUP BY and friends. Expected rows first, answers behind a tap. Bowl to your
field.
1. Economy rates
2026 bowlers who bowled at least 72 legal balls (12 overs): balls, runs conceded (off the bat plus wides and no-balls; byes and leg-byes don't count against the bowler), wickets, and economy (runs per six balls, two decimals). Best economy first.
| PLAYER_NAME | BALLS | RUNS | WICKETS | ECONOMY |
|---|---|---|---|---|
| Logan Pryce | 120 | 139 | 7 | 6.95 |
| Imraan Patel | 107 | 128 | 8 | 7.18 |
| Tom Blackwood | 141 | 171 | 7 | 7.28 |
| Will Ashdown | 144 | 176 | 2 | 7.33 |
| Sione Fifita | 114 | 140 | 5 | 7.37 |
| Waqas Jamil | 108 | 134 | 8 | 7.44 |
| Andile Zulu | 108 | 140 | 5 | 7.78 |
| Kemar Joseph | 108 | 140 | 8 | 7.78 |
| Haris Raza | 110 | 144 | 6 | 7.85 |
| Jack Mercer | 136 | 178 | 10 | 7.85 |
| Gokul Prakash | 138 | 181 | 6 | 7.87 |
| Naveen Reddy | 125 | 170 | 9 | 8.16 |
| Freddie Lowe | 138 | 189 | 7 | 8.22 |
| Arvind Selvam | 138 | 191 | 5 | 8.3 |
| Zubair Lodhi | 120 | 167 | 8 | 8.35 |
| Asif Mirza | 115 | 164 | 6 | 8.56 |
| Archie Muir | 114 | 164 | 5 | 8.63 |
| Ethan Park | 102 | 147 | 4 | 8.65 |
| Senthil Murugan | 135 | 196 | 5 | 8.71 |
| Nico Tamihana | 118 | 172 | 5 | 8.75 |
| Tyler Vance | 85 | 124 | 1 | 8.75 |
| Yusuf Moosa | 120 | 175 | 7 | 8.75 |
| Rory Paterson | 118 | 176 | 9 | 8.95 |
| Wian Brits | 116 | 173 | 5 | 8.95 |
| Kyle Fourie | 106 | 164 | 4 | 9.28 |
| Harish Kumar | 138 | 221 | 9 | 9.61 |
| Callum Reid | 139 | 227 | 2 | 9.8 |
| Omar Haddad | 90 | 148 | 2 | 9.87 |
| Danish Ansari | 104 | 186 | 4 | 10.73 |
| Nikhil Rao | 86 | 157 | 2 | 10.95 |
Try itShow the answer
select p.player_name,
sum(b.is_legal) as balls,
sum(b.runs_batter + case when b.extra_type in ('WD', 'NB') then b.runs_extras else 0 end) as runs,
sum(b.is_bowler_wicket) as wickets,
round(6 * sum(b.runs_batter + case when b.extra_type in ('WD', 'NB') then b.runs_extras else 0 end)
/ sum(b.is_legal), 2) as economy
from cr_balls_v b
join cr_players p on p.player_id = b.bowler_id
where b.season = 2026
group by p.player_name
having sum(b.is_legal) >= 72
order by economy, p.player_name;
select player_name, balls, runs, wickets, round(6 * runs / balls, 2) as economy
from (select p.player_name,
sum(o.balls) as balls,
sum(o.runs) as runs,
sum(o.wickets) as wickets
from (select bowler_id, match_id, over_no,
sum(is_legal) as balls,
sum(runs_batter + case when extra_type in ('WD', 'NB') then runs_extras else 0 end) as runs,
sum(is_bowler_wicket) as wickets
from cr_balls_v
where season = 2026
group by bowler_id, match_id, over_no) o
join cr_players p on p.player_id = o.bowler_id
group by p.player_name)
where balls >= 72
order by economy, player_name;
Count legal balls rather than overs: the last over of a chase (or of an all-out innings) can stop after two or three balls, and counting it as a whole over would flatter the bowler. The second answer aggregates twice, balls into overs and overs into bowlers, which gives the same totals.
2. Boundaries by phase
For each season, the number of fours and sixes in each phase, with a season total. Use
ROLLUP, and label the total "All phases".
| SEASON | PHASE | FOURS | SIXES |
|---|---|---|---|
| 2025 | Death | 84 | 58 |
| 2025 | Middle | 190 | 80 |
| 2025 | Powerplay | 174 | 37 |
| 2025 | All phases | 448 | 175 |
| 2026 | Death | 60 | 43 |
| 2026 | Middle | 195 | 85 |
| 2026 | Powerplay | 214 | 55 |
| 2026 | All phases | 469 | 183 |
Try itShow the answer
select b.season,
case when grouping(b.phase) = 1 then 'All phases' else b.phase end as phase,
sum(b.is_four) as fours,
sum(b.is_six) as sixes
from (select season, is_four, is_six,
case when over_no <= 6 then 'Powerplay' when over_no >= 17 then 'Death' else 'Middle' end as phase
from cr_balls_v) b
group by b.season, rollup (b.phase)
order by b.season, grouping(b.phase), b.phase;
select b.season,
case when grouping(b.phase) = 1 then 'All phases' else b.phase end as phase,
sum(b.is_four) as fours,
sum(b.is_six) as sixes
from (select season, is_four, is_six,
case when over_no <= 6 then 'Powerplay' when over_no >= 17 then 'Death' else 'Middle' end as phase
from cr_balls_v) b
group by grouping sets ((b.season, b.phase), (b.season))
order by b.season, grouping(b.phase), b.phase;
(The b. prefixes avoid the alias trap from page 3.1.) GROUP BY season, ROLLUP (phase) is a partial rollup: season is always grouped, phase is rolled up
within it, so there's no grand total row.
3. Toss decisions
How often did toss winners choose to bat and to field, and how often did that choice win the match?
| TOSS_DECISION | TIMES | TOSS_WINNER_WON |
|---|---|---|
| BAT | 11 | 5 |
| FIELD | 21 | 15 |
Try itShow the answer
select toss_decision,
count(*) as times,
count(case when winner_id = toss_winner_id then 1 end) as toss_winner_won
from cr_matches
group by toss_decision
order by toss_decision;
select toss_decision,
count(*) as times,
sum(case when winner_id = toss_winner_id then 1 else 0 end) as toss_winner_won
from cr_matches
group by toss_decision
order by toss_decision;
Part 3 quiz
5 questions on all of Part 3. Get 4 right to pass. Retake it as often as you like.