An important pattern-matching operator is the "!" or "Not" operator.
In the previous query, a sequence of events was detected (a stock trade for MSFT followed by a stock trade for AAPL). Use the "Not" to detect a "non-event", that is an event in one stream that is not followed by an event in another stream. This permits the detection of missing events from a variety of sequences:
INSERT INTO MsftNoAapl 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];
This query finds any trade for MSFT which is not 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 pattern matching with non-events will be the timestamp when the matching interval expires after the initial event is detected.