Chapter 8 Working With Continuous Queries : Explicit Window Example

Explicit Window Example
If you are familiar with SQL, you know that the order in which the clauses are presented in a query string is not the order in which they are processed. For example, here is a fairly complex example formatted to make each clause distinct:

 
select
    tick.symbol, trade.counterpartyId, avg(tick.volume), count(*),
from
    /Trade trade,
    /StockTick
      {policy: maintain last 5 sliding
         where symbol = "TIBX" or symbol = "GOOG"
         by symbol}
    tick
where
    trade.settlestatus = "FULLY_SETTLED"
    and
    trade.securityId = tick.symbol
 
group by
    tick.symbol,
    trade.counterpartyId
 
having
    count(*) > 2;

 
In fact, the clauses are processed in the following order, as shown in Figure 1, How a Query String is Processed: from (including stream clause), where, group by (including having), select.
Of special interest is how the where clause in the stream policy operates with the main where clause; and how the stream policy can create multiple windows.
Figure 1 How a Query String is Processed