Group By中Case分类统计
Select CollCode,CoalKindCode,
isnull(Count(MarkedCardState),0) Total,
isnull(sum(case MarkedCardState when '1' then 1 else 0 end),0) Normal,
isnull(sum(case MarkedCardState when '2' then 1 else 0 end),0) Used,
isnull(sum(case MarkedCardState when '3' then 1 else 0 end),0) Losed
From VT_MarkedCard
Group By CollCode,CoalKindCode
isnull(Count(MarkedCardState),0) Total,
isnull(sum(case MarkedCardState when '1' then 1 else 0 end),0) Normal,
isnull(sum(case MarkedCardState when '2' then 1 else 0 end),0) Used,
isnull(sum(case MarkedCardState when '3' then 1 else 0 end),0) Losed
From VT_MarkedCard
Group By CollCode,CoalKindCode
Group By 统计中,可以进行Case分类SUM统计。