日期:2014-05-18 浏览次数:20416 次
declare @T table (设备A varchar(4),设备B varchar(6),设备C varchar(6),回复状态 varchar(5)) insert into @T select null,'正常','坏','True' union all select '正常','已修复','正常','False' union all select '坏',null,'已修复','False' union all select '坏','正常','坏','False' select sum(case when 设备A='已修复' or 设备A='正常' then 1 else 0 end) as 设备A正常或已修复的记录, sum(case when 设备A='坏' or 设备A is null then 1 else 0 end) as 设备A非正常和未修复的记录, sum(case when 设备B='已修复' or 设备B='正常' then 1 else 0 end) as 设备B正常或已修复的记录, sum(case when 设备B='坏' or 设备B is null then 1 else 0 end) as 设备B非正常和未修复的记录, sum(case when 设备C='已修复' or 设备C='正常' then 1 else 0 end) as 设备C正常或已修复的记录, sum(case when 设备C='坏' or 设备C is null then 1 else 0 end) as 设备C非正常和未修复的记录 from @T where 回复状态='False'