Skip to main content

avg (Aggregate Function)

Calculates the average for all the events.

Syntax

<DOUBLE> avg(<INT|LONG|DOUBLE|FLOAT> arg)

Query Parameters

NameDescriptionDefault ValuePossible Data TypesOptionalDynamic
argThe value that need to be averaged.INT LONG DOUBLE FLOATNoYes

Example

@info(name = 'query1')
INSERT INTO barStream
SELECT avg(temp) AS avgTemp
FROM fooStream WINDOW TUMBLING_TIME;

This query processes records from the fooStream using a tumbling time-based window. For each window, it calculates the average of the temp values using the avg function. The result is aliased as avgTemp and inserted into the barStream.

Essentially, this query computes the average temperature for each time-based window of records in the fooStream and inserts the resulting average value into the barStream.