Possible Duplicate:
Rails: select unique values from a column
Lets say I have 5000 records that were created in the last two years (2011 & 2012). How can I loop through all those records and return an array of only the unique years [2011, 2012]?
I’m creating a report where rows are labeled by each year that records exit and columns are labeled by months. Then td is populated by sum totals for each month of each year.
see Rails: select unique values from a column for a more rails approach..
edited:
for your specific requirment you can do