;with cte as(select case when total < 100 then '< 100' when total >= 100 and total < 1000 then '>= 100 and < 1000' when total >= 1000 and total < 10000 then '>= 1000 and < 10000' when total >= 10000 then '>= 10000' end as value, totalfrom Acct_sum)select value, COUNT(value) as NumberOfAccounts, SUM(total) as Totalfrom ctegroup by value