Learn SQL/Beginner/Aggregate Functions/SQL Aggregate Functions

SQL Aggregate Functions

Collapse many rows into a single summary value — how many, how much, what's the average.

What & Why

An aggregate function takes a whole column of values and reduces it to one number: a count, a total, an average, a minimum, a maximum. This lesson series covers the five you'll use constantly: COUNT, SUM, AVG, MIN, MAX.

See How It Works

idnamechannelspendstart_dateend_datestatustarget_segment
1Spring Launchgoogle_ads55000.002024-01-152024-03-31activesmb
2Retention Webinaremail45000.002024-02-102024-04-15activeenterprise
3Finance Retargetinglinkedin50000.002024-03-122024-05-31activeenterprise
4Enterprise Searchgoogle_ads60000.002024-04-012024-06-30activeenterprise
EXAMPLE QUERY
SELECT COUNT(*) AS campaign_count, AVG(spend) AS avg_spend
FROM marketing.campaigns;
RESULT — 4 rows collapsed into 1
campaign_countavg_spend
452500.00

The result uses the same Queryflo columns shown in the worked example.

Now You Try

Practice this concept

Marketing wants a one-row email delivery summary with send count, total recipients, and total clicks.

Available schema
marketing

Prefix tables with marketing.table_name.

send_counttotal_recipientstotal_clicks
marketing.email_sends
ColumnType
idinteger
campaign_idinteger
sent_attimestamp with time zone
recipientsinteger
opensinteger
clicksinteger
unsubscribesinteger
bouncesinteger
legacy_send_grouptext
query.sql
Beginner business practice

Sign up free to try it on a real business scenario