0
Well I have the following table structure:
Categoria | DataOp | Tipo | ValorOp
--------------------------------------------------
Carro | 2012-01-14 | 1 | 10
Moto | 2012-01-17 | 1 | 200
Venda | 2012-03-15 | 2 | 500
Carro | 2012-04-24 | 1 | 10
Moto | 2012-04-10 | 1 | 35
Internet | 2012-01-11 | 1 | 98
Well I want to make one select
return me the sum of the totals of each month of type 1:
The result would have to be this:
Mes | Total
----------------------------
01 | 308
04 | 45
I think the select
would look something like this:
SELECT
DataOp,
SUM(ValorOp)
FROM
ResumoReceitaDespesas
GROUP BY DataOp
But here it groups by month.
--------------- Solution --------------
SELECT
MONTH(DataOp),
SUM(ValorOp)
FROM
ResumoReceitaDespesas
WHERE Tipo = '1'
GROUP BY DataOp
I didn’t understand the group by city. Use the function
MONTH()
or maybe it’s betterYEAR()
andMONTH()
.– anonimo
I fumbled at the end of the question. Anyway your solution worked.
– Hugo Borges