select t.range as [profit range], count(*) as [number of occurences]
from (
select case
when profit between 100000000 and 200000000 then '100 million - 200 million'
when profit between 200000000 and 300000000 then '200 million - 300 million'
.
.
.
when profit between 1000000000 and 2000000000 then '1000 million - 2000 million'
else 'Greater then 2000 milions' end as range
from tbl_profit) t
group by t.range
Order by SUBSTR(t.range,1,LOCATE(‘million’,t.range)-1)
You can extract starting number from range using SUBSTR()
and LOCATE
functions and order result according to extracted number