Trigger(like) event in MySQL calculating values from current and previous row -


i have mysql database table in raw metrics data being stored concerning total number of commits on different (web)services. looks this:

 id,  timestamp,                service_name, commits,  tps   001, 2014-03-10  09:00:00,     servicea,     1000   002, 2014-03-10  09:00:00,     serviceb,     1300     003, 2014-03-10  09:00:30,     servicea,     1800   004, 2014-03-10  09:00:30,     serviceb,     1700 

the last column (avg transactions/second) not yet populated. want accomplish values in column calculated upon insertion of snapshot of different service commits (all same timestamp).

the calculation be: (servicex commits current insert - servicex commits previous insert) / (servicex timestamp current insert - servicex timestamp previous insert).

in end want plot calculated tps per service in pchart (already working when filling in tps myself!)

i did researching about: triggering, calculating/computing columns , maybe creating new database view. i'm unsure how procede next , hope of can point me in right direction.

the database used solely presenting these service metrics on monitor screen it's not used else.

thanks in advance.

coif sure order of insertion, can use trigger (before insert), you:

a) select row last service b) update new.tps computation

the trigger better option because column computed once (no need updates/recomputation).


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -