SQL Flow Field Guide

Summarize rows by group

Use GROUP BY and aggregate functions to report one summary row per team.

What you are trying to do

A service lead needs the ticket count and total work minutes for each team.

Work through it

  1. Identify Team as the group key.
  2. Count and sum the source rows inside each team.
  3. Compare the totals with the individual input rows.

Check your work

Care has 3 tickets and 45 minutes. Ops has 1 ticket and 10 minutes.

Practice SQL

Open in SQL Flow
SELECT Team, COUNT(*) AS TicketCount, SUM(Minutes) AS TotalMinutes
FROM (VALUES (1, N'Care', 15), (2, N'Care', 25), (3, N'Ops', 10), (4, N'Care', 5)) AS Ticket(TicketId, Team, Minutes)
GROUP BY Team
ORDER BY Team;

Knowledge check

Commands in this lesson

Next lesson Filter groups with HAVING