Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'd need a very nasty recursive query to accomplish this in purely "functional" way. I don't profess to be clever enough to construct such a query, let alone make it performant.</p> <p>On the other hand, allowing side-effects (i.e. temporary table) significantly simplifies things. You should even be able to make it fairly quick by adding appropriate indexes on the temporary table (not shown here). Here is the actual SQL:</p> <pre><code>CREATE GLOBAL TEMPORARY TABLE EVENT_MASTER_TMP ( EVENT_ID BIGINT NOT NULL, EVENT_TIME BIGINT NOT NULL, DATA_F1 VARCHAR(40), DATA_F2 VARCHAR(40), PRIMARY KEY (EVENT_ID) ); INSERT INTO EVENT_MASTER_TMP SELECT * FROM (SELECT * FROM EVENT_MASTER ORDER BY EVENT_TIME) E WHERE NOT EXISTS ( SELECT * FROM EVENT_MASTER_TMP T WHERE E.DATA_F1 = T.DATA_F1 AND E.DATA_F2 = T.DATA_F2 AND E.EVENT_TIME - T.EVENT_TIME &lt;= 5*60 ); SELECT * FROM EVENT_MASTER_TMP; </code></pre> <p>In plain English:</p> <ul> <li>Go through events from older to newer,</li> <li>for each event, check if it is redundant relative to some row that is already in the temporary table</li> <li>and if not, insert it in the temporary table, so it can be used as a criteria for the remaining events.</li> </ul> <p>Executing this on your test data yields:</p> <pre><code>25327 1297824698 8604 A 25328 1297824770 8604 I 25331 1297824809 8604 1 25332 1297824811 8604 GREY 25341 1297824875 8804 GREY 25342 1297824876 8604 G 25348 1297824930 8604 YELLOW 25350 1297824940 8604 25353 1297824954 8604 B 25361 1297825003 8604 2 25364 1297825026 8604 F </code></pre> <p>Lowering the time threshold from <code>5*60</code> to, say, <code>233</code>, yield this:</p> <pre><code>25327 1297824698 8604 A 25328 1297824770 8604 I 25331 1297824809 8604 1 25332 1297824811 8604 GREY 25341 1297824875 8804 GREY 25342 1297824876 8604 G 25348 1297824930 8604 YELLOW 25350 1297824940 8604 25351 1297824944 8604 A &lt;-- 246s difference 25353 1297824954 8604 B 25361 1297825003 8604 2 25364 1297825026 8604 F 25365 1297825045 8604 GREY &lt;-- 234s difference 25366 1297825046 8604 1 &lt;-- 237s difference </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload