1
I need two information I make the first sum
SELECT
FORMAT(ROUND(SUM(CASE WHEN MONTH(periodo) IN (12) AND classificacao = '3.6' THEN IFNULL(debito-credito,NULL) ELSE 0 END)) ,2) AS custo_1,
Right below I need to take the result above and divide by another SUM
FORMAT(ROUND(SUM(CASE WHEN MONTH(periodo) IN (1) AND classificacao = '3.6' THEN IFNULL(debito-credito,NULL) ELSE 0 END)) ,2)
/
FORMAT(ROUND(SUM(CASE WHEN MONTH(periodo) IN (1) AND classificacao = '3.1.01.01' THEN IFNULL(debito-credito,NULL) ELSE 0 END)) - ROUND(SUM(CASE WHEN MONTH(periodo) IN (1) AND classificacao = '3.2.01.01.01' THEN IFNULL(debito-credito,NULL) ELSE 0 END)),2) AS peso_custo_1
FROM tbl_balancete;
How can I use the result of the first sum so I don’t need to use any cost sum code again ?
Could I explain a little better how I can apply in my code, where I would split ? I didn’t get it right
– Andrews Gomes
Now, looking at your code, I would make the temporary table select 3 times passing in the Where its ranking and out, would make the sum and division.
– Victor Freidinger
The little guy responded heavily.
– Gato de Schrödinger