4
I need a SELECT
that brings the sum of data month to month and disappears with the total of the previous months.
In the SELECT
below is bringing the sum month by month.
SELECT DISTINCT MONTH(data_pgto_bx) as mes, SUM(total_bx) FROM gc_baixas
WHERE sit_bx = 3 GROUP BY mes ORDER BY mes ASC
So far so good with the SELECT
above, my problem is a little more complex, I need this SELECT
also add the column total_bx
with previous months. Example:
In month 10 bring the column sum
total_bx
every month until the month 10;In month 11 bring the sum of all months up to month 11;
In SQL Server we have classification functions to do this. In Mysql unfortunately this does not exist. You will have to use some logic using variables. Later I will try to answer your question.
– gmsantos
Just to clarify, you need the monthly partial sum, right?
– Thomas
No Thomas, I need the total sum up to the month, and this select should show month by month with the overall total up to the month.
– Irio Broleis Filho
@Iriobroleisfilho that is, a field that informs the partial sum of the month, and that returns it in the period from month to month (monthly)
– Thomas
Thank you @Thomas. Omni’s response has met my need.
– Irio Broleis Filho