sql - Get last 12 months data from Db with year in Postgres -


i want fetch last 12 months data db, have written query giving me count , month not year means month related year.

my sql :

select count(b.id),date_part('month',revision_timestamp) package  inner join  package_revision b on a.revision_id=b.revision_id    revision_timestamp > (current_date - interval '12 months')  group  date_part('month',revision_timestamp) 

it gives me output

 month | count  -------+-------      7 |     21      8 |      4      9 |     10 

but want year month 7 - 2012, or year in other col, doesn't matter

i believe wanted this:

select to_char(revision_timestamp, 'yyyy-mm'),        count(b.id) package join package_revision b on a.revision_id = b.revision_id revision_timestamp >       date_trunc('month', current_date) - interval '1 year' group 1 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -