title: Grouping and sorting data month wise sorted data showing month and year in ascending order
body: <p>I need to get the data month wise and sorted, for this I tried following query</p>
  
  <pre><code>select to_char(regn_date,'Mon-yyyy') "Month", count(id) "No of Persons" 
  from Person  
  group by to_char(regn_date,'Mon-yyyy')  
  order by to_char(regn_date,'Mon-yyyy')  
  </code></pre>
  
  <p>and the output I get is</p>
  
  <p><strong>Month     Number of Persons</strong></p>
  
  <pre><code>Dec-2011    1383  
  Feb-2012    1230  
  Jan-2012    1409  
  Mar-2012    1495  
  Nov-2011    985  
  Oct-2011    825  
  Sep-2011    742  
  </code></pre>
  
  <p>Ascending sort on a string value i.e order by to_char(regn_date,'Mon-yyyy') asc </p>
  
  <pre><code>select to_char(regn_date,'Mon-yyyy') "Month", count(id) "No of Persons" 
  from Person  
  group by to_char(regn_date,'Mon-yyyy')  
  order by to_char(regn_date,'Mon-yyyy') asc 
  </code></pre>
  
  <p><strong>Month     Number of Persons</strong>  </p>
  
  <pre><code>Dec-2011    1383  
  Feb-2012    1230  
  Jan-2012    1409  
  Mar-2012    1495  
  Nov-2011    985  
  Oct-2011    825  
  Sep-2011    742  
  </code></pre>
  
  <p>Getting the data sorted results in different display of date format</p>
  
  <pre><code> select to_date(to_char(regn_date,'MM-YYYY'),'MM-YYYY') "Month", count(id) "Number  of  Persons" from Person    
   where trunc(regn_date) &lt; '31-MAR-2012'  
   group by to_date(to_char(regn_date,'MM-YYYY'),'MM-YYYY')  
   order by to_date(to_char(regn_date,'MM-YYYY'),'MM-YYYY')asc  
  </code></pre>
  
  <p>Result:<br>
  <strong>Month     Number of Persons</strong>  </p>
  
  <pre><code>9/1/2011    742    
  10/1/2011   825   
  11/1/2011   985    
  12/1/2011   1383    
  1/1/2012    1409    
  2/1/2012    1230    
  3/1/2012    1495   
  </code></pre>
  
  <p>The desired output is date wise sorted data showing month and year in ascending order.</p>
  
  <p><strong>Month     Number of Persons</strong>    </p>
  
  <pre><code>Sep-2011    742    
  Oct-2011    825       
  Nov-2011    985    
  Dec-2011    1383    
  Jan-2012    1409    
  Feb-2012    1230     
  Mar-2012    1495   
  </code></pre>