title: Order query by day / month / year in rails
body: <p>Let me explain want I want to do, I've a table <code>Clicks</code> where all clicks for products are saved. And I want to make a graph of how many times something is clicked by customers.</p>
  
  <p>This graph needs a day, month and year view. </p>
  
  <p>What I need for the graph to work is a hash or an object. </p>
  
  <p>My idea is that I'm getting something like:</p>
  
  <p><code>data( 2012 =&gt; [ 01 =&gt; 100, 02 =&gt; 300, 03 =&gt; 50 etc.], 2011 =&gt; [ 01 =&gt; 100, 02 =&gt; 300, 03 =&gt; 50 etc.])</code></p>
  
  <p>How can I retrieve all the data from a postgresql database in such an order? I would like to get the <code>created_at</code> field and extract the date from there. In a later process, all items from a particular month must be counted. </p>
  
  <p>I'm struggling with this problem quite a bit, could someone push me in the right direction?</p>