Group sum by month and year

1

I have a simple table in a FIREBIRD database:

idCliente: integer    
dataPagamento: date
valor: numeric

How to make a select that adds up all the amounts to be paid by grouping by month and year?

type like this:

select MES_ANO, sum(valor) from pagamento group by MES_ANO

    
asked by anonymous 11.06.2018 / 21:48

1 answer

2

Firebird database solution.

select 
  extract(MONTH from dataPagamento) AS MES,
  extract(YEAR from dataPagamento) AS ANO, 
  sum(valor) 
from pagamento 
group by extract(MONTH from dataPagamento),extract(YEAR from dataPagamento)
    
11.06.2018 / 21:53