Finding a Sequence of Events

Run a pattern-matching query to isolate a sequence of events in your data.

Here is a simple pattern-matching query:

INSERT INTO MsftThenAapl 
SELECT MSFT.tradeid, AAPL.tradeid 
FROM
   (SELECT * from StockTrades WHERE symbol = 'MSFT') as MSFT,
   (SELECT * from StockTrades WHERE symbol = 'AAPL') as AAPL 
MATCHING [5 seconds: MSFT, AAPL];

Note the following important points:


The query finds any trade for MSFT which is then followed by a trade for AAPL within five seconds. Here is an example of the output from this query:



Note that the timestamp associated with the output from the pattern match is the timestamp of the final event. Also notice that it is possible to get more than one match from an event, in which case the event will appear in the output stream multiple times. If two events in the first stream occur before two matching events in the second stream (and all four events occur within the interval), you will get four outputs: MSFT1-AAPL1, MSFT1-AAPL2, MSFT2 -AAPL1, and MSFT2 -AAPL2.


Created March 8, 2010. Send feedback on this help topic to Sybase Technical Publications: pubs@sybase.com