0

I want to MERGE values based on the value of a select from another table. Something like this:

MERGE INTO table1 (column1) key(id) 
    values (select amount from table2 where id = id limit 1 + 
    select column1 from table1 where id = id - 1 limit 1) 
    where id > 0

I want this to happen for each row where id is greater than 0. Additionally, I want the value of column1 in table1 to be the value of column1 in the previous row plus the value of column2 in table2.

I am using H2 database.

Alison
  • 5,630
  • 4
  • 18
  • 26
  • Is this some kind of running total problem when you say "previous row plus..."? H2 supports [running totals using the MySQL syntax](http://stackoverflow.com/questions/664700/calculate-a-running-total-in-mysql). – Thomas Mueller Mar 22 '13 at 05:51
  • Yes, this helps me do what I want. It doesn't set the values of a new table to the result but with this answer I don't need to. Thanks. – Alison Mar 23 '13 at 19:47
  • @ThomasMueller, FYI ... Alison replied to your comment but you probably didn't get notified. – Gili Oct 11 '13 at 20:35

0 Answers0