-1

I have a table like this

enter image description here

I want to replace null values in P by logic

present value of column P =  present value of column S + previous value of column P.

Expected output:

enter image description here

Thanks in advance

Ashok Anumula
  • 1,338
  • 1
  • 4
  • 9

1 Answers1

0

We can achieve this by using variables in mysql

SELECT 
    pur.Id, pur.s,
    (@b := @b + pur.s) - 10 AS p
FROM
    (SELECT @b := 0.0) AS dummy 
  CROSS JOIN
    purchase AS pur
ORDER BY
    Id ;
Ashok Anumula
  • 1,338
  • 1
  • 4
  • 9