Skip to content

sum

Description

Returns the total of all numerical values passed into the function.

  • Can be used in aggregation to compute totals across grouped rows.
  • When used with multiple arguments, returns the sum of all provided values.

Syntax

sum(value: number, ...values: number): number

Arguments

NameTypeRequiredDescription
valuenumbertrueThe first numerical value to add
...valuesnumbertrueOne or more additional numerical values to add

Example

Description

Use case: Calculate total money spent per user

Suppose you want to compute the total amount of money spent by each user.

Example logs

{ "user": "Chris", "product": "Sunglasses", "price": 10 },
{ "user": "Chris", "product": "Car", "price": 1000 },
{ "user": "Dave", "product": "Desk", "price": 250 }

Example query

top 10 user by sum(price)

Example output

usersum_price
Chris1010
Dave250