Below SQL Statement return rows number for each row in a partition.
select R1.CategoryName,
rank = (select count(distinct R2.CategoryName) from categories R2 where R1.CategoryName <= R2.CategoryName) from categories R1 Order by Rank
Below is the result after use the row number sql statement: