2012-09-27 276 views
-1

這是我的腳本。SQL Server 2008 R2分組

select jt.exempt_status as ExemptStatus, COUNT(*) as ExemptCount 
from employee as e 
join job_title as jt 
    on e.job_title = jt.job_title 
group by jt.exempt_status 

在執行時它顯示

ExemptStatus  ExemptCount 
-----------------------------  
E    2 
N    5 

我需要它什麼顯示而無需在jt.exempt_status字段改變值是。

ExemptStatus  ExemptCount 
-----------------------------  
Exempt   2 
Non-Exempt  5 
+2

有包含exempt_status代碼的說明表? –

+0

@Jeff - 爲了完整性,您使用的是什麼RDBMS? SQL Server? MySQL的? PostgreSQL的?還有別的嗎? – LittleBobbyTables

回答

2

選擇它們時,您可以使用CASE表達格式化你的價值觀:

select CASE jt.exempt_status 
    WHEN 'E' THEN 'Exempt' 
    WHEN 'N' THEN 'Non-Exempt' 
    END 
    as ExemptStatus, COUNT(*) as ExemptCount 
from employee as e 
join job_title as jt 
    on e.job_title = jt.job_title 
group by jt.exempt_status