title: Group by month and year in Rails
body: <p>I have query on postgresql and I want to implement in my apps using rails</p>
  
  <pre><code>ActiveRecord::Base.connection.select_rows("SELECT to_char(date,'Mon') as mon, extract(year from date) as yyyy, SUM(CASE WHEN Title = 4 THEN Qty ELSE 0 END) AS sold FROM Transactions WHERE Store_id = 5 AND Product_id = 2 GROUP BY 1,2")
  </code></pre>
  
  <p>I tried on rails console, and result is :</p>
  
  <pre><code>←[1m←[36m (2.0ms)←[0m  ←[1m
  SELECT to_char(date,'Mon') as mon, extract(year from date) as yyyy, SUM(CASE WHEN Title = 4 THEN Qty ELSE 0 END) AS sold FROM Transactions WHERE Store_id = 5 AND Product_id = 2 GROUP BY 1,2 
  ←[0m=&gt; [["Jul", "2013", "113"], ["Oct", "2013", "73"], ["Jun", "2013", "291"], ["Sep", "2013", "13"], [" Aug", "2013", "81"]]
  </code></pre>
  
  <p>The result not order by month-year.</p>
  
  <p>I tried to add <code>ORDER BY 1,2</code> but the result looks like :</p>
  
  <pre><code>←[1m←[36m (10.0ms)←[0m  ←[1m
  SELECT to_char(date,'Mon') as mon, extract(year from date) as yyyy, SUM(CASE WHEN Title = 4 THEN Qty ELSE 0 END) AS sold FROM Transactions WHERE Store_id = 5 AND Product_id = 2 GROUP BY 1,2 ORDER BY 1,2
  ←[0m=&gt; [["Aug", "2013", "81"], ["Jul", "2013", "113"], ["Jun", "2013", "291"], ["Oct", "2013", "73"], ["Sep", "2013", "13"]]
  </code></pre>
  
  <p>Why the result not ordering by month and year?</p>
  
  <p>I think this order by "alphabetical" not date..</p>