Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!