Data Aggregation with Filter

Use the HAVING clause to place a filter on a window.

The example creates an input window named TradeWindow, to which it attaches a File CSV Input adapter named csvInConn1.

The example creates an output window named VwapWindow, which outputs the results of the volume-weighted average price of the trade values processed by TradeWindow. The results are grouped by Symbol. The HAVING clause places a filter condition on TradeWindow that tells the project server to publish vwap results only when the sum of all Volume values for a Symbol is greater than 100,000.

CREATE OUTPUT WINDOW VwapWindow
SCHEMA (Symbol STRING, vwap MONEY(4))
 PRIMARY KEY DEDUCED 
  AS 
	SELECT TradeWindow.Symbol AS Symbol, 
	 SUM(TradeWindow.Price * TradeWindow.Volume) / SUM(TradeWindow.Volume) AS vwap 
	FROM TradeWindow
	GROUP BY TradeWindow.Symbol
	HAVING
	    SUM(TradeWindow.Volume) > 100000;