I have three fields, Amount (dbfield), Previous Amount (customField-> Balance - Amount), Balance (customField-> sum all amounts). How can I calculate the previous amount on each line? If I do Balance - Amount will be good only for the last line ...
calculate previous balance
-
- User
- Posts: 980
First, this is very important: bear in mind that database works per RECORD BASIS.
If you work with MySQL >8 you can use window-functions SUM() OVER...
Otherwise you need to call (sum_all_amounts) for each row using,
Row_Rendered()
$val = ExecuteScalar("call your value");
Note that calling value for each row, not to mention using sum() which is actually group by, is very expensive.
I would suggest to upgrade your machine to MySQL >8 or related MariaDB (I forget which version but they do have this function too).
-
- User
- Posts: 415
I'm using MySql 5.6 in hosting. Then I can't use something like that
SUM(Quantity) OVER (PARTITION BY AccountID ORDER BY ID)
I've already sum all value from custom field whit custom field
custom field
c_Totali->expression->(select ifnull(sum(movcampagna.NumeroPunti),0) from movcampagna where movcampagna.Cliente = movimenti.idCliente)
and add this in Row_Rendered
// set previous balance
$punti = $this->NumeroPunti->CurrentValue;
$totali = $this->c_Totali->CurrentValue;
$saldopre = $totali - $punti;
$this->c_SaldoPre->ViewValue = $saldopre;
sangnandar
->Note that calling value for each row, not to mention using sum() which is actually group by, is very expensive.
this policy applies only to the rows displayed in the listpage right? or for all the rows of the table?