I have an event table that has the following fields:
event_id
event_type
event_time
Given a duration D
and a number k<
Edit: Rearranged whole answer
Now I understand what you expect.
I've created such a test table on my MySQL and this seems to work:
SELECT e2.event_type FROM events e1
JOIN events e2
ON e1.event_time BETWEEN e2.event_time AND (e2.event_time + INTERVAL 10 MINUTE);
GROUP BY e1.event_id, e2.event_type
HAVING count(e2.event_type) >= 5
Basically, for each event you self join events with specified relative time window (from event_time
to event_time
+ window duration), and then you group by e1's even_id
to get emulated floating time window. Also we're gruping by event_type
here because you want to get this field values for each window.
All you need to think through is performance. I'm not sure if it will be efficient enough for a 1M of records.