Hope you are you are using WSO2 CEP 3.1.0. At the moment WSO2 CEP 4.0.0 under development, once WSO2 CEP is released, there will be an RDBMS publisher (output adapter) where you can specify the connection and publish output stream values directly.
You can have an execution plan with a siddhi query to implement the timestamp logic. To learn more about siddhi query language please refer WSO2 Siddhi documentation.enter link description here
Following is a sample execution plan with a siddhi query for check room temperature values for within given time window (1 min) and write average temperature along with room number to output stream. If you want to store those in database you can have an RDBMS publisher (output adapter) for output stream.
/* Enter a unique ExecutionPlan */
@Plan:name('testPlan')
/* Enter a unique description for ExecutionPlan */
-- @Plan:description('ExecutionPlan')
/* define streams and write query here ... */
@Import('inStream:1.0.0')
define stream inStream (temperature double, roomNumber int);
@Export('outStream:1.0.0')
define stream outStream (temperature double, roomNumber int);
from inStream#window.time(1 min)
select avg(temperature) as temperature,roomNumber
group by roomNumber
having temperature>= 70
insert into outStream;