Excel to SQL · Lesson 6 of 12

A pivot table is GROUP BY

In Excel, you'd reach for
fxInsert > PivotTable, field in Rows, SUM in Values

A pivot table takes rows, puts them in buckets (the field you drag to Rows), and totals each bucket (the field in Values). That is exactly GROUP BY.

The column you group by goes in the SELECT too, so you can see which bucket each total belongs to.

SQL GROUP BY explained as an Excel pivot table: orders grouped by region and summed
GROUP BY is a pivot table: rows land in buckets, then each bucket is totalled. Download · Save to Pinterest
Try itEdit the query, then Run
regionordersunits
Asia Pacific165515
Latin America147460
North America151452
Europe137416

4 rows

Two fields in Rows? Group by both: GROUP BY region, product_id. Months in Rows? Group by the month part of the date: GROUP BY substr(order_date, 1, 7) turns 2026-03-14 into 2026-03.

Want a field in Columns too, like regions across the top? That's turning rows into columns: see pivot in SQL.

Your turn

How many customers came from each acquisition_channel? Show the channel and the count as customers, biggest first.

This page on one card

A pivot table is GROUP BY: the Excel way (Insert > PivotTable) and the SQL query, side by side
A pivot table is GROUP BY, on one card: the Excel way and the SQL. Download · Save to Pinterest
The practice data (7 tables)

See every column and sample rows