select count(B.id), date_part('year', revision_timestamp) as year, date_part('month',revision_timestamp) as month from package as A inner join package_revision as B on A.revision_id=B.revision_id where revision_timestamp > (current_date - INTERVAL '12 months') group by date_part('year', revision_timestamp) date_part('month', revision_timestamp)
or
select count(B.id), to_char(revision_timestamp, 'YYYY-MM') as month from package as A inner join package_revision as B on A.revision_id=B.revision_id where revision_timestamp > (current_date - INTERVAL '12 months') group by to_char(revision_timestamp, 'YYYY-MM')
Keep in mind that if you filter revision_timestamp > (current_date - INTERVAL '12 months') , you will get a range from the current date last year (so if today is '2013-09-04' , you will get a range from '2012-09-04' )
source share