Aggregate Functions

Apply first, last, max, and min functions to outgoing data.

The example creates two schemas named TradeSchema and OpenCloseMinMaxSchema, and an input window named TradeWindow, to which it attaches a File CSV Input adapter.

The example then creates an output window named OutOpenCloseMinMax, which uses the structure defined in OpenCloseMinMaxSchema. The SELECT clause returns the first, last, minimum, and maximum values from the data in TradeWindow, and groups the results by Symbol.

		
CREATE OUTPUT Window OutOpenCloseMinMax 
	SCHEMA OpenCloseMinMaxSchema
	PRIMARY KEY DEDUCED 
AS 
	SELECT 
	    TradeWindow.Symbol       as Symbol,
	    first(TradeWindow.Price) as OpenPrice,
	    last(TradeWindow.Price)  as ClosePrice,
	    min(TradeWindow.Price)   as MinPrice,
	    max(TradeWindow.Price)   as MaxPrice
	
	FROM TradeWindow
	GROUP BY TradeWindow.Symbol;