any idea guys how to sum previous row to next row in different column?...i'm using mysql 5.6... or is there a way using datagridview?

any idea guys how to sum previous row to next row in different column?...i'm using mysql 5.6... or is there a way using datagridview?

Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Sep 23, 2022, 8:55 AM EDT
can you test it?
decimal pre_overd=0.0m; decimal amtd=0.0m; for (int i=1;i<dgv.Rows.Count;i++) { pre_overd=0.0m; decimal.TryParse(dgv["trx_overdue",i-1).Value.ToString(), out pre_overd); amtd=0.0m; decimal.TryParse(dgv["trx_amtdue",i).Value.ToString(), out amtd); dgv["trx_overdue",i).Value = pre_overd + amtd; }Vishal JoshiRank #377 · 6.7K reputationPosted Sep 23, 2022, 10:22 PM EDT
Hello Anand,
You can try the below query to get the expected result.
SELECT s.Id,s.trx_amtdue, s.trx_amt, SUM(s.trx_overdue + s.trx_amtdue) OVER (ORDER BY s.Id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS trx_overdue FROM tblTransaction AS s ORDER BY Id;