title: How to get count of people based on age groups using SQL query in Oracle database?
body: <p>Suppose I have a following query (which a part of my actual query) which retrieves person_id and age for that person:</p>
  
  <pre><code>select p.person_id,TRUNC ((SYSDATE - p.birth_date) / 365.25, 0) AS age
  from person p
  </code></pre>
  
  <p>Now after getting this age I want to get the number of people in each age group like:</p>
  
  <pre><code> group                count
  age &lt;=5                100
  age &gt;5 and age &lt;=10    50
   age &gt; 10              15
     ...                ...
  </code></pre>
  
  <p>I can use group by clause to get count for individual age. But how to get count between two ages?</p>
  
  <p>Can someone tell me the way in which I can do it?</p>
  
  <p>you can use following data for your reference:</p>
  
  <pre><code>   pid    age
      1      4
      2      13
      3      10
      4      8
      5      9 
      6      12
  </code></pre>
  
  <p>So the result should be:</p>
  
  <pre><code>   group      count
     age &lt; =5     1
     &gt;5 &amp; &lt;=10    3
     &gt; 10         2
  </code></pre>