Код: Выделить всё
Select DISCIP,
SUM(TOTAL) as TOTAL,
SUM(COMP) as DONE,
SUM(REM) as REM
from (
select
case when Discipline in ('ELECTRICAL','F&G','INSTRUMENTATION','TELECOM','HVAC') then 'E&I'
when Discipline in ('PIPING') then 'PIPING'
when Discipline in ('EQUIPMENT') then 'EQUIPMENT'
when Discipline in ('MECHANICAL COMPLETION') then 'MC'
else 'OTHERS' end as DISCIP,
Count(TagNo) as TOTAL,
Count(case when Completed=1 then 1 else null end) as COMP,
Count(case when (Completed!=1 or Completed is null) then 1 else null end) as REM
from
com.WBS
where (NA=0 or NA IS NULL)
group by Discipline)t
group by t.DISCIP
Вот результат:

Подробнее здесь: https://stackoverflow.com/questions/791 ... l-grouping