is a capital Greek sigma, and it means add up.

Say it: the sum, from i equals 1 to 4, of i.

It has exactly four parts, and every sigma you ever meet has these four: the index, the variable that changes, usually , , or ; where it starts; where it stops, which is inclusive — it does include 4; and the body, which is what to add up, written in terms of the index.

Mechanically: take the body, substitute , then , and so on to the stop value, and add the results. So

The body does not have to mention the index:

Read that again, because it is the single most useful fact in the series: summing 1 counts things.

And the empty sum is 0. If the stop is before the start there is nothing to add, and the answer is zero, not undefined: .

Summing over a set

This is the form that matters for data, and it is a small change. Instead of counting the index from a number to a number, you let it range over the elements of a set.

Say it: the sum, over every x in S, of x. With that is .

Why this form is the important one: a table has no natural numbering. Rows are not numbered 1 to n; they are just there. Writing the sum over says "do this once for each element", which is exactly what you want, and it does not require you to invent an order that does not exist.

Two consequences worth memorizing:

Counting is summing ones, and the sum over an empty set is zero.

Now the first real one. Total revenue across the whole database:

Work it through with the four lines from note one: .

Summing with a condition

Put a condition under the sigma and only the matching elements are added:

Say it: the sum over x in S with x greater than 3, of x. With that is . You will also see it written on one line, . Same thing.

This is `WHERE`. And it is interchangeable with set-builder — these two are identical:

The first reads better, so prefer it. But knowing they are the same is what lets you move a filter around inside a bigger formula without breaking it — which is exactly what a query planner does, and for the same reason.