数据库:sql server2008
代码:
select mytype,COUNT(*) as thecount from (
select
(case
when isNull((AllPay+performancePay ),0) >= 0 and isNull((AllPay+performancePay ),0) < 5000 then 'A'
when isNull((AllPay+performancePay ),0) >= 5000 and isNull((AllPay+performancePay ),0) < 10000 then 'B'
when isNull((AllPay+performancePay ),0) >= 10000 and isNull((AllPay+performancePay ),0) < 20000 then 'C'
when isNull((AllPay+performancePay ),0) >= 20000 and isNull((AllPay+performancePay ),0) < 30000 then 'D'
when isNull((AllPay+performancePay ),0) >= 30000 and isNull((AllPay+performancePay ),0) < 50000 then 'E'
when isNull((AllPay+performancePay ),0) >= 50000 then 'F'
else 'H' end) as mytype
from CFAppcommon.dbo.pubEmployee pe
left join CliffordHR.dbo.rspay rs on rs.EmpNo = pe.EmpNo
join CFAppcommon.dbo.pubDept pd on pd.DeptID = pe.DeptID
where pd.CompNo = 'CF001') t
group by mytype
order by mytype
效果: