Group sum by month and year

Asked

Viewed 1,020 times

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 amounts payable, grouping by month and year?

kind of:

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

1 answer

2


Solution for Firebird database.

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)
  • unknown function TO_CHAR

  • 1

    It was bad, I confused with Oracle, I’m correcting, the function is date_format. I’ll edit the answer

  • sorry man, my mistake... is that I am working with two databases here. the correct database is Firebird

  • 1

    To extract Month and year in Firebird is this command Extract(MONTH from dataPagamento) AS MES, Extract(YEAR from dataPagamento) AS ANO,

Browser other questions tagged

You are not signed in. Login or sign up in order to post.