php - insert data with add previous row data in a column -


may easy way cant this.i try sum()in insert operation not working. have table name amount.

   id      total_amount         1         200             2         400               3         600             4         800              5         1000       

i want when i'll insert value in total_amount it'll insert , sum previous data. suppose if want add 500 in total amount it'll insert 1500.

   id      total_amount    6         1500      

if want add 300 insert 1800

   id      total_amount    7         1800      

how can this?

you want use insert statement along query:

insert t(id, total_amount)     select max(id)+1, sum(total_amount) + 300     t; 

this setting value of id. if auto_increment, unnecessary.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -