select Dept, SalaryType, Count(*) as Tally from (SELECT Dept, CASE When Salary >= 60000 then 'Rich' else 'Poor' end as SalaryType from TableName) As TempList GROUP BY Dept, SalaryType ORDER BY Dept, SalaryType