How do I get the total amount per month of records from a field in a table.
I have 2 tables, customer and activity, within activity have cost (double) field and as foreign key customer id, want to show the customer and the sum of the cost given for a date.
I made the query to sum the cost value when the date is 2016-01, in this case January I want to show every month, January, February, March ....
select idcliente,
nombre,
sum(costo) as costo
from actividad
inner join cliente
on actividad.cliente_idcliente = cliente.idcliente
where cliente_idcliente = 82
group by fecha=2016-01;
and that this consultation applies to all my clients not just one
EXAMPLE: i want show a table like this https://i.sstatic.net/c8VAX.jpg
use month function
select
YEAR(fecha) as Anno
MONTH(fecha) as Mes,
min(idcliente),
min(nombre),
sum(costo) as costo
from actividad
inner join cliente on actividad.cliente_idcliente=cliente.idcliente
where cliente_idcliente=82
group by year(fecha), month(fecha)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With