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.
try group by:
select extract(year from created),responsible,count(1)
from tablename
group by responsible,extract(year from created)