sum

sum — aggregate function to calculate the sum of a range of values.

SYNOPSIS

sum (expr)

DESCRIPTION

This function computes a value for each record from the specified column of a base table, and returns the sum of those values.

When the field type is timestamp, summing members of the field follows the rules for adding timestamps as shown in the table in timestamp Data Type. That is, you cannot sum an aggregate of two or more absolute timestamps. However, you can sum an aggregate field composed of all interval timestamps, or one composed of exactly one absolute timestamp plus one or more interval timestamps.

The argument expr must include the name of a column in a LiveView table, where that column's data type is int, long, double, or timestamp. The returned value is of the same data type.

When the field type is timestamp, summing members of the field follows the rules for adding timestamps as shown in the table in timestamp Data Type. That is, you cannot sum an aggregate of two or more absolute timestamps. However, you can sum an aggregate field composed of all interval timestamps, or one composed of exactly one absolute timestamp plus one or more interval timestamps.

EXAMPLE

This example shows how to use dynamic aggregation to find the sum of the values in a column. In the Hello LiveView sample, create a query that finds the sum of the quantityRemaining field from the ItemsSales table, grouping by Item. Follow these steps:

  1. In LiveView Desktop connected to a server running the Hello LiveView sample, select the ItemsSales table from the Tables pane of the LiveView Tables view.

  2. In the Select field, enter:

    Item, sum(quantityRemaining) AS totalQty
  3. In the Query field, enter the following:

    group by Item
  4. Click Open Query.

The query results open in a grid view. LiveView Server recalculates the sum whenever the rows returned by the query predicate change.

SEE ALSO

This LiveView aggregate function is based on the sum aggregate function in the StreamBase expression language.