Use an event cache in an output window.
The example creates an input window named Trades and an output window named Last5MinuteStats.
The examples uses the DECLARE block to place an event cache on the Trades window. As a result, the Last5MinuteStats window retains the last 300 seconds of data for every symbol cached.
DECLARE eventCache(Trades[Symbol], 300 seconds) stats; END AS SELECT Trades.Symbol AS symbol, max(stats.Price) AS MaxPrice, sum(stats.Shares) AS Volume FROM Trades GROUP BY Trades.Symbol;
The example creates an output window named Last10TradesStats and uses the DECLARE block to place another event cache on the Trades window. As a result, the Last10TradesStats window retains the last 10 trades for every symbol cached in the Trades window.
CREATE OUTPUT WINDOW Last10TradesStats SCHEMA ( symbol STRING, MaxPrice MONEY(4), Volume LONG) PRIMARY KEY DEDUCED DECLARE eventCache(Trades[Symbol], 10 events) stats; END AS SELECT Trades.Symbol AS symbol, max(stats.Price) AS MaxPrice, sum(stats.Shares) AS Volume FROM Trades GROUP BY Trades.Symbol;