當我運行此查詢:SQL案例
select
'1992' = CASE WHEN Year(HireDate) = 1992 THEN count(*) END,
'1993' = CASE WHEN Year(HireDate) = 1993 THEN count(*) END,
'1994' = CASE WHEN Year(HireDate) = 1994 THEN count(*) END
from employees
group by Year(HireDate)
我得到:
1992 1993 1994
3 NULL NULL
NULL 3 NULL
NULL NULL 3
我如何更改查詢來獲取:
1992 1993 1994
3 3 3
'max(case wehn ...' –