1
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 to each line that is coming back.
My problems are two:
The variable when I place in a column only shows the result as an integer and not as a decimal, I need the decimal pro calculo.
I think since it’s not returning the decimal, it’s messing up the calculation.
Does anyone know why MYSQL round the variable in the column since the result is a decimal?
Result of the query 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
The variables are
decimal
orfloat
?– Ricardo Pontual
You are declaring viable as float or real?
– Luiz Santos
@Ricardopunctual I’m declaiming at the beginning of the select with: SET @ weight := 0 ; SET @ gain := 0;
– Low Rider
@Luizsantos At the beginning of my select I do it using SET. When you talk about float or real, could you give me an example? Thanks.
– Low Rider
data, text la please
– Luiz Santos