Aggregates
Aggregate
sum()
Calculates the sum value for all tuples in arg.
Arguments & returns
8 overloadssum(arg)
Aggregate
Example
Haybarn WASM 1.5.5-rc3 · In your browser
Engine example with sample data · Run to view results.
In a query
Give your timestamps a rhythm.
Group events into calendar months with date_trunc. The same pattern works for days, weeks, and years.
Haybarn WASM 1.5.5-rc3 · In your browser
Guide recipe · Run to view results.
In other engines
Used in larger rewrites 1
These examples use sum as one part of a larger SQL translation.
Snowflake
SELECT * FROM produce PIVOT(SUM(produce.sales) FOR produce.quarter IN ('Q1', 'Q2'))
SELECT * FROM produce PIVOT(SUM(sales) FOR quarter IN ('Q1' AS "'Q1'", 'Q2' AS "'Q2'"))