Build and check a grouped report
Count real matches, calculate totals, and filter groups after aggregation.
Report open workload per team
Run the example database setup if you are starting here. Group at the team level, count a non-null ticket key, and total the estimated hours. Keep the number of known estimates visible so a missing estimate cannot silently become completed work.
SELECT g.name,
COUNT(t.id) AS open_tickets,
COUNT(t.hours) AS estimated_tickets,
SUM(t.hours) AS known_hours
FROM team AS g
LEFT JOIN ticket AS t ON t.team_id = g.id AND t.state = 'open'
GROUP BY g.id, g.name
ORDER BY g.id;
North returns 2 open tickets, 1 estimated ticket, and 3 known hours. South and West each return zero tickets, zero estimates, and NULL hours. COUNT(*) would include a placeholder row for each unmatched team. Use COALESCE on SUM only when the report explicitly defines an empty sum as zero.
Try it
Show teams with at least two open tickets by inserting HAVING COUNT(t.id) >= 2 after GROUP BY. North remains. WHERE filters input rows before grouping. HAVING tests the resulting groups. Group by stable identity even when different teams happen to share a display name.
Build and check a grouped report quiz
Answer 3 questions. Check each answer for an explanation.