table - MySQL Divide two rows and add into new column -


i have mysql table in want perform following operation.

  id     com      com_sub year    parameter       value 6             a1     2010     profit      33766.18 20            a1     2010     revenues    2793617.12 30            a1     2011     profit      84310.73 54            a1     2009     profit      129129.5284 60            a1     2011     revenues    2049157.294 70      b       b1     2010     profit      3753765490 76      b       b1     2010     revenues    217326.7561  

now need manipulate , make dis

  id     com      com_sub year    parameter       value          new value 6              a1     2010    profit         33766.18       0.0123 20             a1     2010    revenues       2793617.12 30             a1     2011    profit         84310.73       0.0252 54             a1     2009    profit         129129.5284     60             a1     2011    revenues       2049157.294 70      b        b1     2010    profit         3753765490     1.235 76      b        b1     2010    revenues       217326.7561  

this means whenever have common year , common com_sub value in row need add division of both values.

assuming table called nanuet, should it:

alter table nanuet add newvalue decimal(6,2);  update nanuet n1 join nanuet n2 on n1.c1=n2.c1     set n1.newvalue = n1.value/n2.value     n1.id<n2.id; 

if there more 2 rows same value of c1 results hard predict.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -