How to GROUP results BY month in Postgres

SELECT date_part('month'::text,rap.fecha)as mes, count(rap.idrapport) as total_mes
FROM rapports rap
JOIN consumidores con ON( con.idconsumidor = rap.idconsumidor )
JOIN usuarios usu ON( usu.idusuario = con.idusuario AND usu.idusuario=5)
WHERE rap.fecha BETWEEN '25-08-2010' and '31-12-2012'
GROUP BY date_part('month'::text, rap.fecha)
ORDER BY 1
Tagged with:
Posted in Programación