select Sno=count(*), c1.categoryid from category c1 INNER JOIN category c2 ON c1.categoryid >= c2.categoryid group by c1.categoryid order by [Sno]