Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda