Technology

MYSQL event_scheduler

//first thing to do, turn on the MYSQL event_scheduler
SET GLOBAL event_scheduler = ON;

//check the status man!
SHOW GLOBAL VARIABLES like ‘event_scheduler’;

//create the event man!…
CREATE EVENT e_hourly
ON SCHEDULE
EVERY 1 hour
COMMENT ‘Update Average Value every hour.’
DO
INSERT INTO data_avg_minute SELECT CURRENT_TIMESTAMP(), avg(temperature),avg(sunradiation) ,avg(voltage1),avg(current1) ,avg(voltage2) ,avg(current2),avg(tc) FROM data WHERE moment >= ‘CURRENT_TIMESTAMP() – interval 1 hour’ AND moment <='CURRENT_TIMESTAMP()';

//if you want to stop the event.. just drop it..
drop event e_hourly;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s