cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting Previously Updated Row in Current Row (within the same query)?

I have a situation where I need to select a previous row's UPDATED value to be used in calculating the current row's value... and then that is used to calculate the next row's value, so on, and so on...

 

I am using the LAG function successfully- however, no matter how I write my query it seems to only pull ALL the previous values FIRST, then update each row after that separately. I need it to:

  1. update the current value

  2. move to the next row, grab the previous row's value (from step 1)

  3. update the current row's value using the value from the previous row

 

I have tried the entire formula all within a single statement, select queries in sub-queries, joins, sub-joins, etc.

Anyone have any advice on how to perform this? Is this a stored procedure of sorts?
Thank you!

AlessioDidier
Member
3 REPLIES 3

 Let us first create a table −mysql> create table DemoTable(Value int); Query OK, 0 rows affected (1.79 sec)Insert some records in the table ...hotmail

kareem35
Member

Try adding these following tables first

 

mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), species VARCHAR(20), CHAR(1), birth DATE, death DATE) eliminare account instagram

dannielll
Member

I think the antique SIM hosted payment form appeared a lot better. I haven't had a threat to examine the the options for customizing the Accept Hosted charge shape but (programmatically) however I'm hoping there's approaches to enhance it for black pomeranian.

hsdse33
Member