日期:2014-05-18 浏览次数:20667 次
select 产品类型, sum(产品跟单状态id), sum(case when 客户反馈满意度id ='4' or 客户反馈满意度id ='5' then 客户反馈满意度id else 0 end ), sum(客户回访方式id) from 表 group by 产品类型
------解决方案--------------------
declare @t table (t nvarchar(16),id1 tinyint,id2 tinyint,id3 tinyint) insert into @t select '苹果3代', 1, 5, 2 union all select '三星5830',3 ,5 ,1 union all select '三星9100', 3, 3, 3 union all select '苹果4代', 2 ,2 ,3 union all select '诺基亚L800', 1 ,2, 2 union all select '苹果4代', 3 ,4, 1 union all select '三星5830', 3 ,3 ,1 union all select '苹果3代', 5 ,1, 2 select t as [产品类型], sum(case when id1 = 3 then 1 else 0 end) as [跟单状态], sum(case when id2 >= 4 then 1 else 0 end) as [客户满意度] , count(1) as [客户的回复次数], sum(case when id2 >= 4 then 1 else 0 end)*100.0/(select count(1) from @t) as [满意度百分比值] from @t group by t /* (8 行受影响) 产品类型 跟单状态 客户满意度 客户的回复次数 满意度百分比值 ---------------- ----------- ----------- ----------- --------------------------------------- 诺基亚L800 0 0 1 0.000000000000 苹果3代 0 1 2 12.500000000000 苹果4代 1 1 2 12.500000000000 三星5830 2 1 2 12.500000000000 三星9100 1 0 1 0.000000000000 (5 行受影响) */
------解决方案--------------------