I have the following SELECT:
SET @peso := 0;
SET @ganho := 0;
SELECT
@peso := (SELECT SUM(peso)/1000 FROM entrada WHERE entrada_id = A.entrada_id)+@ganho AS peso,
@peso,
@ganho := (SELECT SUM(ganho)/1000 FROM entrada WHERE entrada_id = A.entrada_id) AS ganho,
@ganho
FROM
entrada AS A
WHERE
A.entrada_id IN (18, 19,20, 21,22)
GROUP BY
A.entrada_id
I start the "weight" and the "gain" with 0 and I have to apply the sum of the weight + gain for each line that is returning.
My problem is two:
The variable when I put in a column only shows the result as an integer and not as a decimal, I need the decimal pro calculation.
I think that since it's not returning the decimal, it's messing up the calculation.
Does anyone know why MYSQL rounds the variable in the column since the result is a decimal?
Query Result Below:
peso @peso ganho @ganho
852.1890056 852 0.031025076 0
852.1889198 852 1.714096448 1
853.8719912 854 2.465015896 2
854.6229106 856 2.83135176 2