I am using the following query to compute a running balance for my credit card. My bank does not provide running balance column on its website, so I am using a SQL query to compute it myself. This code works for me, except my IDE shows the following warning message, "Setting user variables within expressions is deprecated and will be removed in a future release. Consider alternatives: 'SET variable=expression, ...', or 'SELECT expression(s) INTO variables(s)'".
SET @running_sum = 100;
SELECT
post_date,
category,
amount,
(@running_sum := @running_sum + amount) AS running_total
FROM credit_card;
I also noticed the following statement under MySQL version 8 section 9.4 User-Defined Variables, "Previous releases of MySQL made it possible to assign a value to a user variable in statements other than SET. This functionality is supported in MySQL 8.0 for backward compatibility but is subject to removal in a future release of MySQL".
From these messages it appears to me that MySQL does not like that I am using this expression within my query (@running_sum := @running_sum + amount)
. However, I can't fully understand how am I supposed to re-write this query, so I can achieve the same result of computing running balance, and comply with MySQL version 8 code style.
Thank you in advance for your response.