Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
Double FOR in Postgres

I have a table with some employee, the date of creation and the person in charge.

Name   | Created       | responsible
Jose     2017-01-01      Pedro
Lorena   2017-03-01      Pedro
Ana      2016-01-12      Pedro
Luis     2015-01-23      Ana

I need to draw with an sql, for each year and responsible the number of creations

year   |   responsible   |    Creations
2017       Pedro                2
2016       Pedro                1
2015       Ana                  1

I understand that I should do a double loop for each year (extracted from the creation date) and responsible. And then the record sum for that year and responsible for putting it in the new field "Creations"

I do not know how to put all the pieces together at the same time, the query is bigger, but with that small example, to see the syntax and fit all the pieces, would be of great help.

Many thanks to whoever can help me.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

try group by:

select extract(year from created),responsible,count(1) 
from tablename 
group by responsible,extract(year from created)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda