One approach, although verbose, is to define each aggregate column with a case statement as the argument to summarize. Then the "group by" and "order by" clauses only need to be given "id_agente" and "nombre". I've used this approach several times with Oracle data.
The below query is untested, and it makes some assumptions, but it should at least be a good start.
select a.id_agente id_agente,
a.NOMBRE nombre,
sum(case when to_char(to_date(dec.FECHA_RECOGIDA_ORIGEN,'dd/mm/yyyy'),'mm') = '01' then 1 else 0 end) ene,
sum(case when to_char(to_date(dec.FECHA_RECOGIDA_ORIGEN,'dd/mm/yyyy'),'mm') = '02' then 1 else 0 end) feb,
sum(case when to_char(to_date(dec.FECHA_RECOGIDA_ORIGEN,'dd/mm/yyyy'),'mm') = '03' then 1 else 0 end) mar,
sum(case when to_char(to_date(dec.FECHA_RECOGIDA_ORIGEN,'dd/mm/yyyy'),'mm') = '04' then 1 else 0 end) abr,
sum(case when to_char(to_date(dec.FECHA_RECOGIDA_ORIGEN,'dd/mm/yyyy'),'mm') = '05' then 1 else 0 end) may,
sum(case when to_char(to_date(dec.FECHA_RECOGIDA_ORIGEN,'dd/mm/yyyy'),'mm') = '06' then 1 else 0 end) jun,
sum(case when to_char(to_date(dec.FECHA_RECOGIDA_ORIGEN,'dd/mm/yyyy'),'mm') = '07' then 1 else 0 end) jul,
sum(case when to_char(to_date(dec.FECHA_RECOGIDA_ORIGEN,'dd/mm/yyyy'),'mm') = '08' then 1 else 0 end) ago,
sum(case when to_char(to_date(dec.FECHA_RECOGIDA_ORIGEN,'dd/mm/yyyy'),'mm') = '09' then 1 else 0 end) sep,
sum(case when to_char(to_date(dec.FECHA_RECOGIDA_ORIGEN,'dd/mm/yyyy'),'mm') = '10' then 1 else 0 end) oct,
sum(case when to_char(to_date(dec.FECHA_RECOGIDA_ORIGEN,'dd/mm/yyyy'),'mm') = '11' then 1 else 0 end) nov,
sum(case when to_char(to_date(dec.FECHA_RECOGIDA_ORIGEN,'dd/mm/yyyy'),'mm') = '12' then 1 else 0 end) dic
from dec
group by id_agente,
nombre
order by id_agente,
nombre;
However, using a pivot query, like Dark Anavger mentioned, would likely be the most formal approach if your output format needs to be a single row with twelve summary columns.
Good luck!
sorry. – Eduardo S. Mar 03 '15 at 14:08