title: Get Count of Subcategories who has no other subcategories
body: <p>I am working on a system in which I have a list of categories and subcategories. I have followed the given db structure for this:</p>
  
  <pre><code>category_id | category_name | Parent_id
       1              India         0
       2              US            0
       3              Mumbai        1
       4              Delhi         1
       5              New Delhi     4
  </code></pre>
  
  <p>Now I have two main categories (India and US) and 3 subcategories of these two parent categories. I want to calculate the count of subcategories, which has no further subcategories, of the top most parent element i.e India and US</p>
  
  <p>For e.g</p>
  
  <pre><code>   India
    /      \
  Mumbai  Delhi
              \
             New Delhi
             /      \
           N1        N2
  </code></pre>
  
  <p>Now, I want parent id jsons with a count of subcategories who has no other subcategories.
  In this case count should be 2 because Mumbai has no subcategories and New Delhi has no subcategories. </p>
  
  <pre><code>{"category_name" : "India", "Count" =&gt; "3"} // (Mumbai , N1, N2 because they have no further subcategories)
  </code></pre>
  
  <p>It should be done in loop for all the parent categories. I am trying to use get it using recursive function but not getting exact results.
  Any help?</p>
  
  <p><strong>EDIT:</strong>
  I have similar SQLFIDDLE for it but it is showing only the count of subcategories. I want count of subcategories which has no further subcategories.
  Please refer to given link.
  <a href="http://sqlfiddle.com/#!2/19814/1" rel="nofollow">SQL Fiddle</a></p>